[ARVADOS] created: 738c46babb430153b2e931ed0dd2ca0c34478579

Git user git at public.curoverse.com
Fri Jun 30 09:49:42 EDT 2017


        at  738c46babb430153b2e931ed0dd2ca0c34478579 (commit)


commit 738c46babb430153b2e931ed0dd2ca0c34478579
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Jun 30 09:48:31 2017 -0400

    11910: Ensure test passes despite race between old and new events.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curoverse.com>

diff --git a/services/ws/session_v0_test.go b/services/ws/session_v0_test.go
index 4a2da80..1213be5 100644
--- a/services/ws/session_v0_test.go
+++ b/services/ws/session_v0_test.go
@@ -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{}{}
 		}
 	}()
 }

commit 42de8da89d2966796e0065d6f7eebbe7ef632327
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Jun 29 10:56:32 2017 -0400

    11910: Fix racy tests: ignore non-matching logs from previous tests.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curoverse.com>

diff --git a/services/ws/session_v0_test.go b/services/ws/session_v0_test.go
index 0ae8ceb..4a2da80 100644
--- a/services/ws/session_v0_test.go
+++ b/services/ws/session_v0_test.go
@@ -88,23 +88,17 @@ func (s *v0Suite) TestLastLogID(c *check.C) {
 		close(uuidChan)
 	}()
 
-	done := make(chan bool)
 	go func() {
 		for uuid := range uuidChan {
 			for _, etype := range []string{"create", "blip", "update"} {
 				lg := s.expectLog(c, r)
-				c.Check(lg.ObjectUUID, check.Equals, uuid)
+				for lg.ObjectUUID != uuid {
+					lg = s.expectLog(c, r)
+				}
 				c.Check(lg.EventType, check.Equals, etype)
 			}
 		}
-		close(done)
 	}()
-
-	select {
-	case <-time.After(10 * time.Second):
-		c.Fatal("timeout")
-	case <-done:
-	}
 }
 
 func (s *v0Suite) TestPermission(c *check.C) {
@@ -117,16 +111,21 @@ func (s *v0Suite) TestPermission(c *check.C) {
 	}), check.IsNil)
 	s.expectStatus(c, r, 200)
 
-	uuidChan := make(chan string, 1)
+	uuidChan := make(chan string, 2)
 	go func() {
 		s.token = arvadostest.AdminToken
-		s.emitEvents(nil)
+		s.emitEvents(uuidChan)
 		s.token = arvadostest.ActiveToken
 		s.emitEvents(uuidChan)
 	}()
 
+	wrongUUID := <-uuidChan
+	rightUUID := <-uuidChan
 	lg := s.expectLog(c, r)
-	c.Check(lg.ObjectUUID, check.Equals, <-uuidChan)
+	for lg.ObjectUUID != rightUUID {
+		c.Check(lg.ObjectUUID, check.Not(check.Equals), wrongUUID)
+		lg = s.expectLog(c, r)
+	}
 }
 
 func (s *v0Suite) TestSendBadJSON(c *check.C) {
@@ -170,7 +169,9 @@ func (s *v0Suite) TestSubscribe(c *check.C) {
 
 	for _, etype := range []string{"create", "blip", "update"} {
 		lg := s.expectLog(c, r)
-		c.Check(lg.ObjectUUID, check.Equals, uuid)
+		for lg.ObjectUUID != uuid {
+			lg = s.expectLog(c, r)
+		}
 		c.Check(lg.EventType, check.Equals, etype)
 	}
 }
@@ -228,8 +229,17 @@ func (s *v0Suite) expectStatus(c *check.C, r *json.Decoder, status int) {
 
 func (s *v0Suite) expectLog(c *check.C, r *json.Decoder) *arvados.Log {
 	lg := &arvados.Log{}
-	c.Check(r.Decode(lg), check.IsNil)
-	return lg
+	ok := make(chan struct{})
+	go func() {
+		c.Check(r.Decode(lg), check.IsNil)
+		close(ok)
+	}()
+	select {
+	case <-time.After(10 * time.Second):
+		panic("timed out")
+	case <-ok:
+		return lg
+	}
 }
 
 func (s *v0Suite) testClient() (*server, *websocket.Conn, *json.Decoder, *json.Encoder) {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list