@@ -49,27 +49,23 @@ func waitForCount(t *testing.T, num int) {
49
49
}
50
50
51
51
func releaseOneEntry (t * testing.T , inFlight []* ArchiveRequest ) {
52
- var nowQueued , numQueued int
52
+ var numQueued int
53
53
54
54
numQueued = len (archiveInProgress )
55
55
56
- // Release one, then wait up to 10 seconds for it to complete.
57
- queueMutex .Lock ()
56
+ // Release one, then WaitForCompletion. We'll get signalled when ready.
57
+ // This works out to be quick and race-free, as we'll get signalled when the
58
+ // archival goroutine proceeds to dequeue the now-complete archive but we
59
+ // can't pick up the queue lock again until it's done removing it from
60
+ // archiveInProgress. We'll remain waiting on the queue lock in
61
+ // WaitForCompletion() until we can safely acquire the lock.
62
+ LockQueue ()
58
63
archiveQueueReleaseCond .Signal ()
59
- queueMutex .Unlock ()
60
- timeout := time .Now ().Add (10 * time .Second )
61
- for {
62
- nowQueued = len (archiveInProgress )
63
- if nowQueued != numQueued || time .Now ().After (timeout ) {
64
- break
65
- }
66
- }
67
-
68
- // Make sure we didn't just timeout.
69
- assert .NotEqual (t , numQueued , nowQueued )
64
+ WaitForCompletion ()
65
+ UnlockQueue ()
70
66
71
67
// Also make sure that we released only one.
72
- assert .Equal (t , numQueued - 1 , nowQueued )
68
+ assert .Equal (t , numQueued - 1 , len ( archiveInProgress ) )
73
69
}
74
70
75
71
func TestArchive_Basic (t * testing.T ) {
@@ -187,15 +183,7 @@ func TestArchive_Basic(t *testing.T) {
187
183
assert .Equal (t , 2 , len (archiveInProgress ))
188
184
releaseOneEntry (t , inFlight )
189
185
assert .Equal (t , 1 , len (archiveInProgress ))
190
-
191
- // Test waiting for completion on one, which should be relatively
192
- // straightforward. We'll hold the queue-lock and release an entry. It will
193
- // wait to acquire the queue lock, which we'll drop when we
194
- // WaitForCompletion(), to be woken up later.
195
- LockQueue ()
196
186
releaseOneEntry (t , inFlight )
197
- WaitForCompletion ()
198
- UnlockQueue ()
199
187
assert .Equal (t , 0 , len (archiveInProgress ))
200
188
201
189
zipReq2 = DeriveRequestFrom (ctx , firstCommit + ".zip" )
0 commit comments