Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(740)

Issue 10433043: Helper: test a function for correct locking. (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 11 months ago by jtv.canonical
Modified:
10 years, 9 months ago
Reviewers:
mp+170477, thumper, jameinel
Visibility:
Public.

Description

Helper: test a function for correct locking. (The diff still includes that of https://codereview.appspot.com/10433043 for which I haven't had a second review vote yet — please ignore that part here, and focus on testLockingFunction(), its uses, and its tests.) This is the outcome of discussion at https://code.launchpad.net/~jtv/juju-core/create-gwacl-sessions/+merge/170032 but produces a helper that is much, much simpler. It could become generic, although one thing is still missing: it currently only works for locks that are of type sync.Mutex. It probably ought to work for any type of lock. Failure of a function to acquire the right lock(s) is a constant risk in concurrent programs, so one of the things most worth testing, but it's also relatively hard to test for and so nobody ever does it. Of course if you can forget the locking you can also forget the test, but this helper makes it very easy to guard against regressions. https://code.launchpad.net/~jtv/juju-core/generic-locking-test/+merge/170477 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 7
Unified diffs Side-by-side diffs Delta from patch set Stats (+167 lines, -1 line) Patch
A [revision details] View 1 chunk +2 lines, -0 lines 0 comments Download
M environs/azure/environ.go View 3 chunks +34 lines, -1 line 0 comments Download
M environs/azure/environ_test.go View 3 chunks +131 lines, -0 lines 7 comments Download

Messages

Total messages: 5
jtv.canonical
Please take a look.
10 years, 11 months ago (2013-06-20 02:21:14 UTC) #1
thumper
LGTM for what it is, but might be nice to have as a checker. https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go ...
10 years, 11 months ago (2013-06-20 02:47:22 UTC) #2
jtv.canonical
> LGTM for what it is, but might be nice to have as a checker. ...
10 years, 11 months ago (2013-06-20 08:39:29 UTC) #3
jameinel
LGTM though maybe it could be tweaked a bit. https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go File environs/azure/environ_test.go (right): https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go#newcode57 environs/azure/environ_test.go:57: ...
10 years, 11 months ago (2013-06-20 08:48:08 UTC) #4
jtv.canonical
10 years, 11 months ago (2013-06-20 09:53:06 UTC) #5
On 2013/06/20 08:48:08, jameinel wrote:
> LGTM though maybe it could be tweaked a bit.

Thanks for the review.  I'm in a bottleneck now where I want to unblock my team
in a hurry, so your reviews are really appreciated.


> environs/azure/environ_test.go:57: <-proceed

> 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.

Good idea.  Done.


> 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?

I can't add the GoSched calls because the code won't compile on 1.0.  But I
added thumper's sleep(0) calls, with a note that they should be GoSched calls
once we're on 1.1 or better.


>
https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go...
> environs/azure/environ_test.go:70: panic(errors.New("function did not obey
> lock"))
> Rather than panic to indicate failures, you could have this function take a c
*C
> and then call c.Assert instead.

Had that originally, but that complicated the testing of the function itself (in
addition to adding the argument of course).  I'm sure there's a way, I just
didn't have time to go yet further down the rabbit hole.


> Or use Tim's idea and make it a Checker.

Lovely idea.  But rabbit hole, bottleneck.


>
https://codereview.appspot.com/10433043/diff/1/environs/azure/environ_test.go...
> 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'd prefer to worry about this later, when we have time to look into that
tradeoff.  Maybe somebody more familiar with the locking API could even take it
on if I don't find time first.

This is exactly the kind of rabbit hole I was trying to avoid by not making this
more widely reusable: every time the scope broadens it needs just a bit more
additional polish, and then that takes it closer to a possibility to broaden the
scope yet further.  Let's just see how this develops in practice for a bit more,
and not over-generalize it at the cost of the really urgent work.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b