diff --git a/Makefile b/Makefile index 6400e06..ee0c9c1 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,10 @@ ifneq ($(TEST),) TESTARGS := $(TESTARGS) -run $(TEST) endif +ifneq ($(COUNT),) +TESTARGS := $(TESTARGS) -count $(COUNT) +endif + hook: [ ! -d "$(CURDIR)/.git/hooks" ] || ln -sf "$(CURDIR)/scripts/pre-commit.hook" "$(CURDIR)/.git/hooks/pre-commit" diff --git a/src/signaling/backend_server_test.go b/src/signaling/backend_server_test.go index fa932b5..d3098bc 100644 --- a/src/signaling/backend_server_test.go +++ b/src/signaling/backend_server_test.go @@ -936,6 +936,10 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) { } else if room.Room.RoomId != roomId { t.Fatalf("Expected room %s, got %s", roomId, room.Room.RoomId) } + + // Give message processing some time. + time.Sleep(10 * time.Millisecond) + if room, err := client2.JoinRoom(ctx, roomId); err != nil { t.Fatal(err) } else if room.Room.RoomId != roomId { @@ -946,53 +950,7 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) { defer hubRoom.Close() } - // We will receive "joined" events for all clients. The ordering is not - // defined as messages are processed and sent by asynchronous NATS handlers. - msg1_1, err := client1.RunUntilMessage(ctx) - if err != nil { - t.Error(err) - } - msg1_2, err := client1.RunUntilMessage(ctx) - if err != nil { - t.Error(err) - } - msg2_1, err := client2.RunUntilMessage(ctx) - if err != nil { - t.Error(err) - } - msg2_2, err := client2.RunUntilMessage(ctx) - if err != nil { - t.Error(err) - } - - if err := client1.checkMessageJoined(msg1_1, hello1.Hello); err != nil { - // Ordering is "joined" from client 2, then from client 1 - if err := client1.checkMessageJoined(msg1_1, hello2.Hello); err != nil { - t.Error(err) - } - if err := client1.checkMessageJoined(msg1_2, hello1.Hello); err != nil { - t.Error(err) - } - } else { - // Ordering is "joined" from client 1, then from client 2 - if err := client1.checkMessageJoined(msg1_2, hello2.Hello); err != nil { - t.Error(err) - } - } - if err := client2.checkMessageJoined(msg2_1, hello1.Hello); err != nil { - // Ordering is "joined" from client 2, then from client 1 - if err := client2.checkMessageJoined(msg2_1, hello2.Hello); err != nil { - t.Error(err) - } - if err := client2.checkMessageJoined(msg2_2, hello1.Hello); err != nil { - t.Error(err) - } - } else { - // Ordering is "joined" from client 1, then from client 2 - if err := client2.checkMessageJoined(msg2_2, hello2.Hello); err != nil { - t.Error(err) - } - } + WaitForUsersJoined(ctx, t, client1, hello1, client2, hello2) var wg sync.WaitGroup diff --git a/src/signaling/hub_test.go b/src/signaling/hub_test.go index 3205bbc..4baae61 100644 --- a/src/signaling/hub_test.go +++ b/src/signaling/hub_test.go @@ -1221,6 +1221,10 @@ func TestClientMessageToRoom(t *testing.T) { } else if room.Room.RoomId != roomId { t.Fatalf("Expected room %s, got %s", roomId, room.Room.RoomId) } + + // Give message processing some time. + time.Sleep(10 * time.Millisecond) + if room, err := client2.JoinRoom(ctx, roomId); err != nil { t.Fatal(err) } else if room.Room.RoomId != roomId { @@ -1665,6 +1669,10 @@ func TestRoomParticipantsListUpdateWhileDisconnected(t *testing.T) { } else if room.Room.RoomId != roomId { t.Fatalf("Expected room %s, got %s", roomId, room.Room.RoomId) } + + // Give message processing some time. + time.Sleep(10 * time.Millisecond) + if room, err := client2.JoinRoom(ctx, roomId); err != nil { t.Fatal(err) } else if room.Room.RoomId != roomId { @@ -1940,6 +1948,10 @@ func TestClientSendOfferPermissions(t *testing.T) { } else if room.Room.RoomId != roomId { t.Fatalf("Expected room %s, got %s", roomId, room.Room.RoomId) } + + // Give message processing some time. + time.Sleep(10 * time.Millisecond) + if room, err := client2.JoinRoom(ctx, roomId); err != nil { t.Fatal(err) } else if room.Room.RoomId != roomId {