11910: Ensure test passes despite race between old and new events.
[arvados.git] / services / ws / session_v0_test.go
index 4a2da8012d8c4fb5bfec46ba08698d4fc4fcc947..1213be5d140555f0a533cfc4aa639ef9959e7db2 100644 (file)
@@ -83,7 +83,15 @@ func (s *v0Suite) TestLastLogID(c *check.C) {
        }), check.IsNil)
        s.expectStatus(c, r, 200)
 
+       avoidRace := make(chan struct{}, cap(uuidChan))
        go func() {
+               // When last_log_id is given, although v0session sends
+               // old events in order, and sends new events in order,
+               // it doesn't necessarily finish sending all old
+               // events before sending any new events. To avoid
+               // hitting this bug in the test, we wait for the old
+               // events to arrive before emitting any new events.
+               <-avoidRace
                s.emitEvents(uuidChan)
                close(uuidChan)
        }()
@@ -97,6 +105,7 @@ func (s *v0Suite) TestLastLogID(c *check.C) {
                                }
                                c.Check(lg.EventType, check.Equals, etype)
                        }
+                       avoidRace <- struct{}{}
                }
        }()
 }