@@ -49,27 +49,23 @@ func waitForCount(t *testing.T, num int) {
4949}
5050
5151func releaseOneEntry (t * testing.T , inFlight []* ArchiveRequest ) {
52- var nowQueued , numQueued int
52+ var numQueued int
5353
5454 numQueued = len (archiveInProgress )
5555
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 ()
5863 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 ()
7066
7167 // Also make sure that we released only one.
72- assert .Equal (t , numQueued - 1 , nowQueued )
68+ assert .Equal (t , numQueued - 1 , len ( archiveInProgress ) )
7369}
7470
7571func TestArchive_Basic (t * testing.T ) {
@@ -187,15 +183,7 @@ func TestArchive_Basic(t *testing.T) {
187183 assert .Equal (t , 2 , len (archiveInProgress ))
188184 releaseOneEntry (t , inFlight )
189185 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 ()
196186 releaseOneEntry (t , inFlight )
197- WaitForCompletion ()
198- UnlockQueue ()
199187 assert .Equal (t , 0 , len (archiveInProgress ))
200188
201189 zipReq2 = DeriveRequestFrom (ctx , firstCommit + ".zip" )
0 commit comments