https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go#newcode76
environs/azure/environ_test.go:76: panic(errors.New("function did not
release lock"))
I would think that supporting the Locker interface might be more useful
than this final assert. I guess the tradeoff is that you would have to
do something like try to acquire the lock, which potentially leaves you
with a hanging test. (Right now if function doesn't release the lock,
you get a panic, the alternative would give you a hanging test).
I just know a fair amount of code uses a RWMutex rather than only a
plain Mutex, and it seems a shame to need to have 2 code paths for
something so similar.
Also, you could use runtime type assertions to still confirm the Mutex
behavior. Just use:
if mutex, ok := lock.(*sync.Mutex); ok {
blankMutex := sync.Mutex{}
...
}
Or even a:
switch lock.(type) {
case *sync.Mutex:
...
case *sync.RWMutex:
...
}
LGTM though maybe it could be tweaked a bit.
https:/ /codereview. appspot. com/10433043/ diff/1/ environs/ azure/environ_ test.go azure/environ_ test.go (right):
File environs/
https:/ /codereview. appspot. com/10433043/ diff/1/ environs/ azure/environ_ test.go# newcode57 azure/environ_ test.go: 57: <-proceed
environs/
You could probably buffer proceed so that function gets a bit more time
to hang itself. We don't need 'function' to *wait* until the main loop
gets to this point, so buffering the channel makes sense to me.
https:/ /codereview. appspot. com/10433043/ diff/1/ environs/ azure/environ_ test.go# newcode60 azure/environ_ test.go: 60: // misbehaved "function" plenty of
environs/
rope to hang itself.
On 2013/06/20 02:47:22, thumper wrote:
> You could have a few sleep(0) type calls, as this should do the same
thing.
runtime.GoSched exists in 1.1, and we want to support using 1.1 (just
not require it).
Is there a reason you can't just add those calls?
https:/ /codereview. appspot. com/10433043/ diff/1/ environs/ azure/environ_ test.go# newcode70 azure/environ_ test.go: 70: panic(errors. New("function did not
environs/
obey lock"))
Rather than panic to indicate failures, you could have this function
take a c *C and then call c.Assert instead.
Or use Tim's idea and make it a Checker.
https:/ /codereview. appspot. com/10433043/ diff/1/ environs/ azure/environ_ test.go# newcode76 azure/environ_ test.go: 76: panic(errors. New("function did not
environs/
release lock"))
I would think that supporting the Locker interface might be more useful
than this final assert. I guess the tradeoff is that you would have to
do something like try to acquire the lock, which potentially leaves you
with a hanging test. (Right now if function doesn't release the lock,
you get a panic, the alternative would give you a hanging test).
I just know a fair amount of code uses a RWMutex rather than only a
plain Mutex, and it seems a shame to need to have 2 code paths for
something so similar.
Also, you could use runtime type assertions to still confirm the Mutex
behavior. Just use:
if mutex, ok := lock.(*sync.Mutex); ok {
blankMutex := sync.Mutex{}
...
}
Or even a:
switch lock.(type) {
case *sync.Mutex:
...
case *sync.RWMutex:
...
}
https:/ /codereview. appspot. com/10433043/