diff --git a/Makefile b/Makefile index ef57b7a..b7d7ea7 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,14 @@ ifneq ($(COUNT),) TESTARGS := $(TESTARGS) -count $(COUNT) endif +ifneq ($(PARALLEL),) +TESTARGS := $(TESTARGS) -parallel $(PARALLEL) +endif + +ifneq ($(VERBOSE),) +TESTARGS := $(TESTARGS) -v +endif + ifeq ($(GOARCH), amd64) GOPATHBIN := $(GOPATH)/bin else @@ -93,18 +101,18 @@ vet: common $(GO) vet $(ALL_PACKAGES) test: vet common - $(GO) test -v -timeout $(TIMEOUT) $(TESTARGS) $(ALL_PACKAGES) + $(GO) test -timeout $(TIMEOUT) $(TESTARGS) $(ALL_PACKAGES) cover: vet common rm -f cover.out && \ - $(GO) test -v -timeout $(TIMEOUT) -coverprofile cover.out $(ALL_PACKAGES) && \ + $(GO) test -timeout $(TIMEOUT) -coverprofile cover.out $(ALL_PACKAGES) && \ sed -i "/_easyjson/d" cover.out && \ sed -i "/\.pb\.go/d" cover.out && \ $(GO) tool cover -func=cover.out coverhtml: vet common rm -f cover.out && \ - $(GO) test -v -timeout $(TIMEOUT) -coverprofile cover.out $(ALL_PACKAGES) && \ + $(GO) test -timeout $(TIMEOUT) -coverprofile cover.out $(ALL_PACKAGES) && \ sed -i "/_easyjson/d" cover.out && \ sed -i "/\.pb\.go/d" cover.out && \ $(GO) tool cover -html=cover.out -o coverage.html diff --git a/api_backend_test.go b/api_backend_test.go index 48f5e41..bcb3213 100644 --- a/api_backend_test.go +++ b/api_backend_test.go @@ -27,6 +27,7 @@ import ( ) func TestBackendChecksum(t *testing.T) { + t.Parallel() rnd := newRandomString(32) body := []byte{1, 2, 3, 4, 5} secret := []byte("shared-secret") @@ -58,6 +59,7 @@ func TestBackendChecksum(t *testing.T) { } func TestValidNumbers(t *testing.T) { + t.Parallel() valid := []string{ "+12", "+12345", diff --git a/api_signaling_test.go b/api_signaling_test.go index cc93ba7..ba8455c 100644 --- a/api_signaling_test.go +++ b/api_signaling_test.go @@ -81,6 +81,7 @@ func testMessages(t *testing.T, messageType string, valid_messages []testCheckVa } func TestClientMessage(t *testing.T) { + t.Parallel() // The message needs a type. msg := ClientMessage{} if err := msg.CheckValid(); err == nil { @@ -89,6 +90,7 @@ func TestClientMessage(t *testing.T) { } func TestHelloClientMessage(t *testing.T) { + t.Parallel() internalAuthParams := []byte("{\"backend\":\"https://domain.invalid\"}") tokenAuthParams := []byte("{\"token\":\"invalid-token\"}") valid_messages := []testCheckValid{ @@ -233,6 +235,7 @@ func TestHelloClientMessage(t *testing.T) { } func TestMessageClientMessage(t *testing.T) { + t.Parallel() valid_messages := []testCheckValid{ &MessageClientMessage{ Recipient: MessageClientMessageRecipient{ @@ -314,6 +317,7 @@ func TestMessageClientMessage(t *testing.T) { } func TestByeClientMessage(t *testing.T) { + t.Parallel() // Any "bye" message is valid. valid_messages := []testCheckValid{ &ByeClientMessage{}, @@ -332,6 +336,7 @@ func TestByeClientMessage(t *testing.T) { } func TestRoomClientMessage(t *testing.T) { + t.Parallel() // Any "room" message is valid. valid_messages := []testCheckValid{ &RoomClientMessage{}, @@ -350,6 +355,7 @@ func TestRoomClientMessage(t *testing.T) { } func TestErrorMessages(t *testing.T) { + t.Parallel() id := "request-id" msg := ClientMessage{ Id: id, @@ -382,6 +388,7 @@ func TestErrorMessages(t *testing.T) { } func TestIsChatRefresh(t *testing.T) { + t.Parallel() var msg ServerMessage data_true := []byte("{\"type\":\"chat\",\"chat\":{\"refresh\":true}}") msg = ServerMessage{ @@ -426,6 +433,7 @@ func assertEqualStrings(t *testing.T, expected, result []string) { } func Test_Welcome_AddRemoveFeature(t *testing.T) { + t.Parallel() var msg WelcomeServerMessage assertEqualStrings(t, []string{}, msg.Features) diff --git a/backend_client_test.go b/backend_client_test.go index 379bcd0..4b043dc 100644 --- a/backend_client_test.go +++ b/backend_client_test.go @@ -70,6 +70,8 @@ func returnOCS(t *testing.T, w http.ResponseWriter, body []byte) { } func TestPostOnRedirect(t *testing.T) { + t.Parallel() + CatchLogForTest(t) r := mux.NewRouter() r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/ocs/v2.php/two", http.StatusTemporaryRedirect) @@ -125,6 +127,8 @@ func TestPostOnRedirect(t *testing.T) { } func TestPostOnRedirectDifferentHost(t *testing.T) { + t.Parallel() + CatchLogForTest(t) r := mux.NewRouter() r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "http://domain.invalid/ocs/v2.php/two", http.StatusTemporaryRedirect) @@ -165,6 +169,8 @@ func TestPostOnRedirectDifferentHost(t *testing.T) { } func TestPostOnRedirectStatusFound(t *testing.T) { + t.Parallel() + CatchLogForTest(t) r := mux.NewRouter() r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/ocs/v2.php/two", http.StatusFound) @@ -217,6 +223,8 @@ func TestPostOnRedirectStatusFound(t *testing.T) { } func TestHandleThrottled(t *testing.T) { + t.Parallel() + CatchLogForTest(t) r := mux.NewRouter() r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) { returnOCS(t, w, []byte("[]")) diff --git a/backend_configuration_test.go b/backend_configuration_test.go index 1ae52ec..b2c2b27 100644 --- a/backend_configuration_test.go +++ b/backend_configuration_test.go @@ -92,6 +92,7 @@ func testBackends(t *testing.T, config *BackendConfiguration, valid_urls [][]str } func TestIsUrlAllowed_Compat(t *testing.T) { + CatchLogForTest(t) // Old-style configuration valid_urls := []string{ "http://domain.invalid", @@ -114,6 +115,7 @@ func TestIsUrlAllowed_Compat(t *testing.T) { } func TestIsUrlAllowed_CompatForceHttps(t *testing.T) { + CatchLogForTest(t) // Old-style configuration, force HTTPS valid_urls := []string{ "https://domain.invalid", @@ -135,6 +137,7 @@ func TestIsUrlAllowed_CompatForceHttps(t *testing.T) { } func TestIsUrlAllowed(t *testing.T) { + CatchLogForTest(t) valid_urls := [][]string{ {"https://domain.invalid/foo", string(testBackendSecret) + "-foo"}, {"https://domain.invalid/foo/", string(testBackendSecret) + "-foo"}, @@ -180,6 +183,7 @@ func TestIsUrlAllowed(t *testing.T) { } func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) { + CatchLogForTest(t) valid_urls := []string{} invalid_urls := []string{ "http://domain.invalid", @@ -197,6 +201,7 @@ func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) { } func TestIsUrlAllowed_AllowAll(t *testing.T) { + CatchLogForTest(t) valid_urls := []string{ "http://domain.invalid", "https://domain.invalid", @@ -222,6 +227,7 @@ type ParseBackendIdsTestcase struct { } func TestParseBackendIds(t *testing.T) { + CatchLogForTest(t) testcases := []ParseBackendIdsTestcase{ {"", nil}, {"backend1", []string{"backend1"}}, @@ -241,6 +247,7 @@ func TestParseBackendIds(t *testing.T) { } func TestBackendReloadNoChange(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1, backend2") @@ -276,6 +283,7 @@ func TestBackendReloadNoChange(t *testing.T) { } func TestBackendReloadChangeExistingURL(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1, backend2") @@ -316,6 +324,7 @@ func TestBackendReloadChangeExistingURL(t *testing.T) { } func TestBackendReloadChangeSecret(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1, backend2") @@ -354,6 +363,7 @@ func TestBackendReloadChangeSecret(t *testing.T) { } func TestBackendReloadAddBackend(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1") @@ -394,6 +404,7 @@ func TestBackendReloadAddBackend(t *testing.T) { } func TestBackendReloadRemoveHost(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1, backend2") @@ -431,6 +442,7 @@ func TestBackendReloadRemoveHost(t *testing.T) { } func TestBackendReloadRemoveBackendFromSharedHost(t *testing.T) { + CatchLogForTest(t) current := testutil.ToFloat64(statsBackendsCurrent) original_config := goconf.NewConfigFile() original_config.AddOption("backend", "backends", "backend1, backend2") @@ -486,6 +498,8 @@ func mustParse(s string) *url.URL { } func TestBackendConfiguration_Etcd(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd, client := NewEtcdClientForTest(t) url1 := "https://domain1.invalid/foo" @@ -619,6 +633,8 @@ func TestBackendConfiguration_Etcd(t *testing.T) { } func TestBackendCommonSecret(t *testing.T) { + t.Parallel() + CatchLogForTest(t) u1, err := url.Parse("http://domain1.invalid") if err != nil { t.Fatal(err) diff --git a/backend_server_test.go b/backend_server_test.go index e2d3f94..3c9f676 100644 --- a/backend_server_test.go +++ b/backend_server_test.go @@ -275,6 +275,8 @@ func expectRoomlistEvent(ch chan *AsyncMessage, msgType string) (*EventServerMes } func TestBackendServer_NoAuth(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTest(t) roomId := "the-room-id" @@ -301,6 +303,8 @@ func TestBackendServer_NoAuth(t *testing.T) { } func TestBackendServer_InvalidAuth(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTest(t) roomId := "the-room-id" @@ -329,6 +333,8 @@ func TestBackendServer_InvalidAuth(t *testing.T) { } func TestBackendServer_OldCompatAuth(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTest(t) roomId := "the-room-id" @@ -378,6 +384,8 @@ func TestBackendServer_OldCompatAuth(t *testing.T) { } func TestBackendServer_InvalidBody(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTest(t) roomId := "the-room-id" @@ -397,6 +405,8 @@ func TestBackendServer_InvalidBody(t *testing.T) { } func TestBackendServer_UnsupportedRequest(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTest(t) msg := &BackendServerRoomRequest{ @@ -423,8 +433,10 @@ func TestBackendServer_UnsupportedRequest(t *testing.T) { } func TestBackendServer_RoomInvite(t *testing.T) { + CatchLogForTest(t) for _, backend := range eventBackendsForTest { t.Run(backend, func(t *testing.T) { + t.Parallel() RunTestBackendServer_RoomInvite(t) }) } @@ -503,8 +515,10 @@ func RunTestBackendServer_RoomInvite(t *testing.T) { } func TestBackendServer_RoomDisinvite(t *testing.T) { + CatchLogForTest(t) for _, backend := range eventBackendsForTest { t.Run(backend, func(t *testing.T) { + t.Parallel() RunTestBackendServer_RoomDisinvite(t) }) } @@ -616,6 +630,8 @@ func RunTestBackendServer_RoomDisinvite(t *testing.T) { } func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client1 := NewTestClient(t, server, hub) @@ -741,8 +757,10 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) { } func TestBackendServer_RoomUpdate(t *testing.T) { + CatchLogForTest(t) for _, backend := range eventBackendsForTest { t.Run(backend, func(t *testing.T) { + t.Parallel() RunTestBackendServer_RoomUpdate(t) }) } @@ -831,8 +849,10 @@ func RunTestBackendServer_RoomUpdate(t *testing.T) { } func TestBackendServer_RoomDelete(t *testing.T) { + CatchLogForTest(t) for _, backend := range eventBackendsForTest { t.Run(backend, func(t *testing.T) { + t.Parallel() RunTestBackendServer_RoomDelete(t) }) } @@ -916,8 +936,10 @@ func RunTestBackendServer_RoomDelete(t *testing.T) { } func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -1047,6 +1069,8 @@ func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) { } func TestBackendServer_ParticipantsUpdateEmptyPermissions(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) @@ -1132,6 +1156,8 @@ func TestBackendServer_ParticipantsUpdateEmptyPermissions(t *testing.T) { } func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client1 := NewTestClient(t, server, hub) @@ -1345,8 +1371,10 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) { } func TestBackendServer_InCallAll(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -1595,6 +1623,8 @@ func TestBackendServer_InCallAll(t *testing.T) { } func TestBackendServer_RoomMessage(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) @@ -1660,6 +1690,8 @@ func TestBackendServer_RoomMessage(t *testing.T) { } func TestBackendServer_TurnCredentials(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, _, _, server := CreateBackendServerForTestWithTurn(t) q := make(url.Values) @@ -1703,6 +1735,7 @@ func TestBackendServer_TurnCredentials(t *testing.T) { } func TestBackendServer_StatsAllowedIps(t *testing.T) { + CatchLogForTest(t) config := goconf.NewConfigFile() config.AddOption("stats", "allowed_ips", "127.0.0.1, 192.168.0.1, 192.168.1.1/24") _, backend, _, _, _, _ := CreateBackendServerForTestFromConfig(t, config) @@ -1720,7 +1753,9 @@ func TestBackendServer_StatsAllowedIps(t *testing.T) { } for _, addr := range allowed { + addr := addr t.Run(addr, func(t *testing.T) { + t.Parallel() r1 := &http.Request{ RemoteAddr: addr, } @@ -1761,7 +1796,9 @@ func TestBackendServer_StatsAllowedIps(t *testing.T) { } for _, addr := range notAllowed { + addr := addr t.Run(addr, func(t *testing.T) { + t.Parallel() r := &http.Request{ RemoteAddr: addr, } @@ -1773,6 +1810,7 @@ func TestBackendServer_StatsAllowedIps(t *testing.T) { } func Test_IsNumeric(t *testing.T) { + t.Parallel() numeric := []string{ "0", "1", @@ -1802,6 +1840,8 @@ func Test_IsNumeric(t *testing.T) { } func TestBackendServer_DialoutNoSipBridge(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) @@ -1860,6 +1900,8 @@ func TestBackendServer_DialoutNoSipBridge(t *testing.T) { } func TestBackendServer_DialoutAccepted(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) @@ -1966,6 +2008,8 @@ func TestBackendServer_DialoutAccepted(t *testing.T) { } func TestBackendServer_DialoutAcceptedCompat(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) @@ -2072,6 +2116,8 @@ func TestBackendServer_DialoutAcceptedCompat(t *testing.T) { } func TestBackendServer_DialoutRejected(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) client := NewTestClient(t, server, hub) diff --git a/backend_storage_etcd_test.go b/backend_storage_etcd_test.go index 5ab6549..6fc0250 100644 --- a/backend_storage_etcd_test.go +++ b/backend_storage_etcd_test.go @@ -52,6 +52,7 @@ func (tl *testListener) EtcdClientCreated(client *EtcdClient) { } func Test_BackendStorageEtcdNoLeak(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { etcd, client := NewEtcdClientForTest(t) tl := &testListener{ diff --git a/backoff_test.go b/backoff_test.go index 95c9294..2bbc55e 100644 --- a/backoff_test.go +++ b/backoff_test.go @@ -28,6 +28,7 @@ import ( ) func TestBackoff_Exponential(t *testing.T) { + t.Parallel() backoff, err := NewExponentialBackoff(100*time.Millisecond, 500*time.Millisecond) if err != nil { t.Fatal(err) diff --git a/capabilities_test.go b/capabilities_test.go index cb94994..eed2b75 100644 --- a/capabilities_test.go +++ b/capabilities_test.go @@ -130,6 +130,8 @@ func SetCapabilitiesGetNow(t *testing.T, f func() time.Time) { } func TestCapabilities(t *testing.T) { + t.Parallel() + CatchLogForTest(t) url, capabilities := NewCapabilitiesForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -192,6 +194,8 @@ func TestCapabilities(t *testing.T) { } func TestInvalidateCapabilities(t *testing.T) { + t.Parallel() + CatchLogForTest(t) var called atomic.Uint32 url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse) { called.Add(1) diff --git a/clientsession_test.go b/clientsession_test.go index 39f2531..43de0e4 100644 --- a/clientsession_test.go +++ b/clientsession_test.go @@ -117,6 +117,7 @@ func Test_permissionsEqual(t *testing.T) { for idx, test := range tests { test := test t.Run(strconv.Itoa(idx), func(t *testing.T) { + t.Parallel() equal := permissionsEqual(test.a, test.b) if equal != test.equal { t.Errorf("Expected %+v to be %s to %+v but was %s", test.a, equalStrings[test.equal], test.b, equalStrings[equal]) @@ -126,6 +127,8 @@ func Test_permissionsEqual(t *testing.T) { } func TestBandwidth_Client(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -198,6 +201,8 @@ func TestBandwidth_Client(t *testing.T) { } func TestBandwidth_Backend(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubWithMultipleBackendsForTest(t) u, err := url.Parse(server.URL + "/one") diff --git a/deferred_executor_test.go b/deferred_executor_test.go index 4cf3d1f..3a3659a 100644 --- a/deferred_executor_test.go +++ b/deferred_executor_test.go @@ -35,6 +35,7 @@ func TestDeferredExecutor_MultiClose(t *testing.T) { } func TestDeferredExecutor_QueueSize(t *testing.T) { + t.Parallel() e := NewDeferredExecutor(0) defer e.waitForStop() defer e.Close() @@ -100,6 +101,7 @@ func TestDeferredExecutor_CloseFromFunc(t *testing.T) { } func TestDeferredExecutor_DeferAfterClose(t *testing.T) { + CatchLogForTest(t) e := NewDeferredExecutor(64) defer e.waitForStop() diff --git a/etcd_client_test.go b/etcd_client_test.go index 7849c38..b87a1df 100644 --- a/etcd_client_test.go +++ b/etcd_client_test.go @@ -143,6 +143,8 @@ func DeleteEtcdValue(etcd *embed.Etcd, key string) { } func Test_EtcdClient_Get(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd, client := NewEtcdClientForTest(t) if response, err := client.Get(context.Background(), "foo"); err != nil { @@ -165,6 +167,8 @@ func Test_EtcdClient_Get(t *testing.T) { } func Test_EtcdClient_GetPrefix(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd, client := NewEtcdClientForTest(t) if response, err := client.Get(context.Background(), "foo"); err != nil { @@ -286,6 +290,8 @@ func (l *EtcdClientTestListener) EtcdKeyDeleted(client *EtcdClient, key string, } func Test_EtcdClient_Watch(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd, client := NewEtcdClientForTest(t) SetEtcdValue(etcd, "foo/a", []byte("1")) diff --git a/flags_test.go b/flags_test.go index 406b2c5..9a00ee9 100644 --- a/flags_test.go +++ b/flags_test.go @@ -97,6 +97,7 @@ func runConcurrentFlags(t *testing.T, count int, f func()) { } func TestFlagsConcurrentAdd(t *testing.T) { + t.Parallel() var flags Flags var added atomic.Int32 @@ -111,6 +112,7 @@ func TestFlagsConcurrentAdd(t *testing.T) { } func TestFlagsConcurrentRemove(t *testing.T) { + t.Parallel() var flags Flags flags.Set(1) @@ -126,6 +128,7 @@ func TestFlagsConcurrentRemove(t *testing.T) { } func TestFlagsConcurrentSet(t *testing.T) { + t.Parallel() var flags Flags var set atomic.Int32 diff --git a/grpc_client_test.go b/grpc_client_test.go index faf5480..1714b1b 100644 --- a/grpc_client_test.go +++ b/grpc_client_test.go @@ -112,6 +112,7 @@ func waitForEvent(ctx context.Context, t *testing.T, ch <-chan struct{}) { } func Test_GrpcClients_EtcdInitial(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { _, addr1 := NewGrpcServerForTest(t) _, addr2 := NewGrpcServerForTest(t) @@ -135,6 +136,8 @@ func Test_GrpcClients_EtcdInitial(t *testing.T) { } func Test_GrpcClients_EtcdUpdate(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd := NewEtcdForTest(t) client, _ := NewGrpcClientsWithEtcdForTest(t, etcd) ch := client.getWakeupChannelForTesting() @@ -189,6 +192,8 @@ func Test_GrpcClients_EtcdUpdate(t *testing.T) { } func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) { + t.Parallel() + CatchLogForTest(t) etcd := NewEtcdForTest(t) client, _ := NewGrpcClientsWithEtcdForTest(t, etcd) ch := client.getWakeupChannelForTesting() @@ -233,6 +238,7 @@ func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) { } func Test_GrpcClients_DnsDiscovery(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { lookup := newMockDnsLookupForTest(t) target := "testgrpc:12345" @@ -289,6 +295,8 @@ func Test_GrpcClients_DnsDiscovery(t *testing.T) { } func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) { + t.Parallel() + CatchLogForTest(t) lookup := newMockDnsLookupForTest(t) target := "testgrpc:12345" ip1 := net.ParseIP("192.168.0.1") @@ -324,6 +332,7 @@ func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) { } func Test_GrpcClients_Encryption(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { serverKey, err := rsa.GenerateKey(rand.Reader, 1024) if err != nil { diff --git a/grpc_server_test.go b/grpc_server_test.go index 232309e..3847c76 100644 --- a/grpc_server_test.go +++ b/grpc_server_test.go @@ -98,6 +98,8 @@ func NewGrpcServerForTest(t *testing.T) (server *GrpcServer, addr string) { } func Test_GrpcServer_ReloadCerts(t *testing.T) { + t.Parallel() + CatchLogForTest(t) key, err := rsa.GenerateKey(rand.Reader, 1024) if err != nil { t.Fatal(err) @@ -178,6 +180,8 @@ func Test_GrpcServer_ReloadCerts(t *testing.T) { } func Test_GrpcServer_ReloadCA(t *testing.T) { + t.Parallel() + CatchLogForTest(t) serverKey, err := rsa.GenerateKey(rand.Reader, 1024) if err != nil { t.Fatal(err) diff --git a/http_client_pool_test.go b/http_client_pool_test.go index 6b6214c..b434789 100644 --- a/http_client_pool_test.go +++ b/http_client_pool_test.go @@ -29,6 +29,7 @@ import ( ) func TestHttpClientPool(t *testing.T) { + t.Parallel() if _, err := NewHttpClientPool(0, false); err == nil { t.Error("should not be possible to create empty pool") } diff --git a/hub_test.go b/hub_test.go index acc488a..a25ca37 100644 --- a/hub_test.go +++ b/hub_test.go @@ -794,6 +794,8 @@ func performHousekeeping(hub *Hub, now time.Time) *sync.WaitGroup { } func TestInitialWelcome(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -817,6 +819,8 @@ func TestInitialWelcome(t *testing.T) { } func TestExpectClientHello(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) // The server will send an error and close the connection if no "Hello" @@ -851,6 +855,8 @@ func TestExpectClientHello(t *testing.T) { } func TestExpectClientHelloUnsupportedVersion(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -879,6 +885,8 @@ func TestExpectClientHelloUnsupportedVersion(t *testing.T) { } func TestClientHelloV1(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -904,6 +912,7 @@ func TestClientHelloV1(t *testing.T) { } func TestClientHelloV2(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -954,6 +963,7 @@ func TestClientHelloV2(t *testing.T) { } func TestClientHelloV2_IssuedInFuture(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -985,6 +995,7 @@ func TestClientHelloV2_IssuedInFuture(t *testing.T) { } func TestClientHelloV2_Expired(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -1015,6 +1026,7 @@ func TestClientHelloV2_Expired(t *testing.T) { } func TestClientHelloV2_IssuedAtMissing(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -1046,6 +1058,7 @@ func TestClientHelloV2_IssuedAtMissing(t *testing.T) { } func TestClientHelloV2_ExpiresAtMissing(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -1077,6 +1090,7 @@ func TestClientHelloV2_ExpiresAtMissing(t *testing.T) { } func TestClientHelloV2_CachedCapabilities(t *testing.T) { + CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) { hub, _, _, server := CreateHubForTest(t) @@ -1130,6 +1144,8 @@ func TestClientHelloV2_CachedCapabilities(t *testing.T) { } func TestClientHelloWithSpaces(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1156,6 +1172,8 @@ func TestClientHelloWithSpaces(t *testing.T) { } func TestClientHelloAllowAll(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTestWithConfig(t, func(server *httptest.Server) (*goconf.ConfigFile, error) { config, err := getTestConfig(server) if err != nil { @@ -1190,8 +1208,10 @@ func TestClientHelloAllowAll(t *testing.T) { } func TestClientHelloSessionLimit(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -1352,6 +1372,8 @@ func TestClientHelloSessionLimit(t *testing.T) { } func TestSessionIdsUnordered(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) publicSessionIds := make([]string, 0) @@ -1425,6 +1447,8 @@ func TestSessionIdsUnordered(t *testing.T) { } func TestClientHelloResume(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1480,6 +1504,8 @@ func TestClientHelloResume(t *testing.T) { } func TestClientHelloResumeExpired(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1535,6 +1561,8 @@ func TestClientHelloResumeExpired(t *testing.T) { } func TestClientHelloResumeTakeover(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -1603,6 +1631,8 @@ func TestClientHelloResumeTakeover(t *testing.T) { } func TestClientHelloResumeOtherHub(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1697,6 +1727,8 @@ func TestClientHelloResumeOtherHub(t *testing.T) { } func TestClientHelloResumePublicId(t *testing.T) { + t.Parallel() + CatchLogForTest(t) // Test that a client can't resume a "public" session of another user. hub, _, _, server := CreateHubForTest(t) @@ -1771,6 +1803,8 @@ func TestClientHelloResumePublicId(t *testing.T) { } func TestClientHelloByeResume(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1836,6 +1870,8 @@ func TestClientHelloByeResume(t *testing.T) { } func TestClientHelloResumeAndJoin(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -1937,6 +1973,7 @@ func runGrpcProxyTest(t *testing.T, f func(hub1, hub2 *Hub, server1, server2 *ht } func TestClientHelloResumeProxy(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) { client1 := NewTestClient(t, server1, hub1) @@ -2029,6 +2066,7 @@ func TestClientHelloResumeProxy(t *testing.T) { } func TestClientHelloResumeProxy_Takeover(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) { client1 := NewTestClient(t, server1, hub1) @@ -2136,6 +2174,7 @@ func TestClientHelloResumeProxy_Takeover(t *testing.T) { } func TestClientHelloResumeProxy_Disconnect(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) { client1 := NewTestClient(t, server1, hub1) @@ -2200,6 +2239,8 @@ func TestClientHelloResumeProxy_Disconnect(t *testing.T) { } func TestClientHelloClient(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -2228,6 +2269,8 @@ func TestClientHelloClient(t *testing.T) { } func TestClientHelloClient_V3Api(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -2261,6 +2304,8 @@ func TestClientHelloClient_V3Api(t *testing.T) { } func TestClientHelloInternal(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -2289,8 +2334,10 @@ func TestClientHelloInternal(t *testing.T) { } func TestClientMessageToSessionId(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -2362,8 +2409,10 @@ func TestClientMessageToSessionId(t *testing.T) { } func TestClientControlToSessionId(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -2435,6 +2484,8 @@ func TestClientControlToSessionId(t *testing.T) { } func TestClientControlMissingPermissions(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -2519,6 +2570,8 @@ func TestClientControlMissingPermissions(t *testing.T) { } func TestClientMessageToUserId(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -2579,6 +2632,8 @@ func TestClientMessageToUserId(t *testing.T) { } func TestClientControlToUserId(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -2639,6 +2694,8 @@ func TestClientControlToUserId(t *testing.T) { } func TestClientMessageToUserIdMultipleSessions(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -2722,8 +2779,10 @@ func WaitForUsersJoined(ctx context.Context, t *testing.T, client1 *TestClient, } func TestClientMessageToRoom(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -2812,8 +2871,10 @@ func TestClientMessageToRoom(t *testing.T) { } func TestClientControlToRoom(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -2902,6 +2963,8 @@ func TestClientControlToRoom(t *testing.T) { } func TestJoinRoom(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -2941,6 +3004,8 @@ func TestJoinRoom(t *testing.T) { } func TestJoinRoomTwice(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -3018,6 +3083,8 @@ func TestJoinRoomTwice(t *testing.T) { } func TestExpectAnonymousJoinRoom(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -3070,6 +3137,8 @@ func TestExpectAnonymousJoinRoom(t *testing.T) { } func TestExpectAnonymousJoinRoomAfterLeave(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -3156,6 +3225,8 @@ func TestExpectAnonymousJoinRoomAfterLeave(t *testing.T) { } func TestJoinRoomChange(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -3208,6 +3279,8 @@ func TestJoinRoomChange(t *testing.T) { } func TestJoinMultiple(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -3286,6 +3359,8 @@ func TestJoinMultiple(t *testing.T) { } func TestJoinDisplaynamesPermission(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -3368,6 +3443,8 @@ func TestJoinDisplaynamesPermission(t *testing.T) { } func TestInitialRoomPermissions(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -3411,6 +3488,8 @@ func TestInitialRoomPermissions(t *testing.T) { } func TestJoinRoomSwitchClient(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client := NewTestClient(t, server, hub) @@ -3536,6 +3615,8 @@ func TestGetRealUserIP(t *testing.T) { } func TestClientMessageToSessionIdWhileDisconnected(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -3627,6 +3708,8 @@ func TestClientMessageToSessionIdWhileDisconnected(t *testing.T) { } func TestRoomParticipantsListUpdateWhileDisconnected(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) client1 := NewTestClient(t, server, hub) @@ -3759,8 +3842,10 @@ func TestRoomParticipantsListUpdateWhileDisconnected(t *testing.T) { } func TestClientTakeoverRoomSession(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() RunTestClientTakeoverRoomSession(t) }) } @@ -3902,6 +3987,8 @@ func RunTestClientTakeoverRoomSession(t *testing.T) { } func TestClientSendOfferPermissions(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -4041,6 +4128,8 @@ func TestClientSendOfferPermissions(t *testing.T) { } func TestClientSendOfferPermissionsAudioOnly(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -4132,6 +4221,8 @@ func TestClientSendOfferPermissionsAudioOnly(t *testing.T) { } func TestClientSendOfferPermissionsAudioVideo(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -4259,6 +4350,8 @@ loop: } func TestClientSendOfferPermissionsAudioVideoMedia(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -4391,8 +4484,10 @@ loop: } func TestClientRequestOfferNotInRoom(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -4607,6 +4702,8 @@ func TestClientRequestOfferNotInRoom(t *testing.T) { } func TestNoSendBetweenSessionsOnDifferentBackends(t *testing.T) { + t.Parallel() + CatchLogForTest(t) // Clients can't send messages to sessions connected from other backends. hub, _, _, server := CreateHubWithMultipleBackendsForTest(t) @@ -4678,6 +4775,8 @@ func TestNoSendBetweenSessionsOnDifferentBackends(t *testing.T) { } func TestNoSameRoomOnDifferentBackends(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubWithMultipleBackendsForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -4787,8 +4886,10 @@ func TestNoSameRoomOnDifferentBackends(t *testing.T) { } func TestClientSendOffer(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -4906,6 +5007,8 @@ func TestClientSendOffer(t *testing.T) { } func TestClientUnshareScreen(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) mcu, err := NewTestMCU() @@ -5000,8 +5103,10 @@ func TestClientUnshareScreen(t *testing.T) { } func TestVirtualClientSessions(t *testing.T) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -5337,8 +5442,10 @@ func TestVirtualClientSessions(t *testing.T) { } func DoTestSwitchToOne(t *testing.T, details map[string]interface{}) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -5474,8 +5581,10 @@ func TestSwitchToOneList(t *testing.T) { } func DoTestSwitchToMultiple(t *testing.T, details1 map[string]interface{}, details2 map[string]interface{}) { + CatchLogForTest(t) for _, subtest := range clusteredTests { t.Run(subtest, func(t *testing.T) { + t.Parallel() var hub1 *Hub var hub2 *Hub var server1 *httptest.Server @@ -5620,6 +5729,8 @@ func TestSwitchToMultipleMixed(t *testing.T) { } func TestGeoipOverrides(t *testing.T) { + t.Parallel() + CatchLogForTest(t) country1 := "DE" country2 := "IT" country3 := "site1" @@ -5657,6 +5768,8 @@ func TestGeoipOverrides(t *testing.T) { } func TestDialoutStatus(t *testing.T) { + t.Parallel() + CatchLogForTest(t) _, _, _, hub, _, server := CreateBackendServerForTest(t) internalClient := NewTestClient(t, server, hub) @@ -5868,6 +5981,8 @@ func TestDialoutStatus(t *testing.T) { } func TestGracefulShutdownInitial(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, _ := CreateHubForTest(t) hub.ScheduleShutdown() @@ -5875,6 +5990,8 @@ func TestGracefulShutdownInitial(t *testing.T) { } func TestGracefulShutdownOnBye(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -5908,6 +6025,8 @@ func TestGracefulShutdownOnBye(t *testing.T) { } func TestGracefulShutdownOnExpiration(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) diff --git a/natsclient_test.go b/natsclient_test.go index 9bef7d9..dfe51af 100644 --- a/natsclient_test.go +++ b/natsclient_test.go @@ -104,6 +104,7 @@ func testNatsClient_Subscribe(t *testing.T, client NatsClient) { } func TestNatsClient_Subscribe(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { client := CreateLocalNatsClientForTest(t) @@ -120,6 +121,7 @@ func testNatsClient_PublishAfterClose(t *testing.T, client NatsClient) { } func TestNatsClient_PublishAfterClose(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { client := CreateLocalNatsClientForTest(t) @@ -137,6 +139,7 @@ func testNatsClient_SubscribeAfterClose(t *testing.T, client NatsClient) { } func TestNatsClient_SubscribeAfterClose(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { client := CreateLocalNatsClientForTest(t) @@ -159,6 +162,7 @@ func testNatsClient_BadSubjects(t *testing.T, client NatsClient) { } func TestNatsClient_BadSubjects(t *testing.T) { + CatchLogForTest(t) ensureNoGoroutinesLeak(t, func(t *testing.T) { client := CreateLocalNatsClientForTest(t) diff --git a/notifier_test.go b/notifier_test.go index 6c983dd..51fc920 100644 --- a/notifier_test.go +++ b/notifier_test.go @@ -118,6 +118,7 @@ func TestNotifierResetWillNotify(t *testing.T) { } func TestNotifierDuplicate(t *testing.T) { + t.Parallel() var notifier Notifier var wgStart sync.WaitGroup var wgEnd sync.WaitGroup diff --git a/proxy/proxy_server_test.go b/proxy/proxy_server_test.go index 69c4acc..7ed87df 100644 --- a/proxy/proxy_server_test.go +++ b/proxy/proxy_server_test.go @@ -93,6 +93,7 @@ func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey) { } func TestTokenInFuture(t *testing.T) { + signaling.CatchLogForTest(t) server, key := newProxyServerForTest(t) claims := &signaling.TokenClaims{ diff --git a/proxy/proxy_tokens_etcd_test.go b/proxy/proxy_tokens_etcd_test.go index 1df97fe..84f6c8b 100644 --- a/proxy/proxy_tokens_etcd_test.go +++ b/proxy/proxy_tokens_etcd_test.go @@ -39,6 +39,8 @@ import ( "github.com/dlintw/goconf" "go.etcd.io/etcd/server/v3/embed" "go.etcd.io/etcd/server/v3/lease" + + signaling "github.com/strukturag/nextcloud-spreed-signaling" ) var ( @@ -160,6 +162,7 @@ func generateAndSaveKey(t *testing.T, etcd *embed.Etcd, name string) *rsa.Privat } func TestProxyTokensEtcd(t *testing.T) { + signaling.CatchLogForTest(t) tokens, etcd := newTokensEtcdForTesting(t) key1 := generateAndSaveKey(t, etcd, "/foo") diff --git a/proxy_config_etcd_test.go b/proxy_config_etcd_test.go index df90fcd..2276f8b 100644 --- a/proxy_config_etcd_test.go +++ b/proxy_config_etcd_test.go @@ -62,6 +62,8 @@ func SetEtcdProxy(t *testing.T, etcd *embed.Etcd, path string, proxy *TestProxyI } func TestProxyConfigEtcd(t *testing.T) { + t.Parallel() + CatchLogForTest(t) proxy := newMcuProxyForConfig(t) etcd, config := newProxyConfigEtcd(t, proxy) diff --git a/proxy_config_static_test.go b/proxy_config_static_test.go index ddbdc8e..ebb8ec2 100644 --- a/proxy_config_static_test.go +++ b/proxy_config_static_test.go @@ -59,6 +59,7 @@ func updateProxyConfigStatic(t *testing.T, config ProxyConfig, dns bool, urls .. } func TestProxyConfigStaticSimple(t *testing.T) { + CatchLogForTest(t) proxy := newMcuProxyForConfig(t) config, _ := newProxyConfigStatic(t, proxy, false, "https://foo/") proxy.Expect("add", "https://foo/") @@ -77,6 +78,7 @@ func TestProxyConfigStaticSimple(t *testing.T) { } func TestProxyConfigStaticDNS(t *testing.T) { + CatchLogForTest(t) lookup := newMockDnsLookupForTest(t) proxy := newMcuProxyForConfig(t) config, dnsMonitor := newProxyConfigStatic(t, proxy, true, "https://foo/") diff --git a/room_ping_test.go b/room_ping_test.go index e570d70..59b705d 100644 --- a/room_ping_test.go +++ b/room_ping_test.go @@ -63,6 +63,7 @@ func NewRoomPingForTest(t *testing.T) (*url.URL, *RoomPing) { } func TestSingleRoomPing(t *testing.T) { + CatchLogForTest(t) u, ping := NewRoomPingForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -113,6 +114,7 @@ func TestSingleRoomPing(t *testing.T) { } func TestMultiRoomPing(t *testing.T) { + CatchLogForTest(t) u, ping := NewRoomPingForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -159,6 +161,7 @@ func TestMultiRoomPing(t *testing.T) { } func TestMultiRoomPing_Separate(t *testing.T) { + CatchLogForTest(t) u, ping := NewRoomPingForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) @@ -201,6 +204,7 @@ func TestMultiRoomPing_Separate(t *testing.T) { } func TestMultiRoomPing_DeleteRoom(t *testing.T) { + CatchLogForTest(t) u, ping := NewRoomPingForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) diff --git a/room_test.go b/room_test.go index 8b239a7..e558675 100644 --- a/room_test.go +++ b/room_test.go @@ -73,6 +73,8 @@ func TestRoom_InCall(t *testing.T) { } func TestRoom_Update(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, router, server := CreateHubForTest(t) config, err := getTestConfig(server) @@ -210,6 +212,8 @@ loop: } func TestRoom_Delete(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, router, server := CreateHubForTest(t) config, err := getTestConfig(server) @@ -352,6 +356,8 @@ loop: } func TestRoom_RoomSessionData(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, router, server := CreateHubForTest(t) config, err := getTestConfig(server) @@ -421,6 +427,8 @@ func TestRoom_RoomSessionData(t *testing.T) { } func TestRoom_InCallAll(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, router, server := CreateHubForTest(t) config, err := getTestConfig(server) diff --git a/single_notifier_test.go b/single_notifier_test.go index 7d593d8..48a1c5a 100644 --- a/single_notifier_test.go +++ b/single_notifier_test.go @@ -118,6 +118,7 @@ func TestSingleNotifierResetWillNotify(t *testing.T) { } func TestSingleNotifierDuplicate(t *testing.T) { + t.Parallel() var notifier SingleNotifier var wgStart sync.WaitGroup var wgEnd sync.WaitGroup diff --git a/test_helpers.go b/test_helpers.go new file mode 100644 index 0000000..6de5d10 --- /dev/null +++ b/test_helpers.go @@ -0,0 +1,49 @@ +/** + * Standalone signaling server for the Nextcloud Spreed app. + * Copyright (C) 2024 struktur AG + * + * @author Joachim Bauch + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package signaling + +import ( + "log" + "testing" +) + +type testLogWriter struct { + t testing.TB +} + +func (w *testLogWriter) Write(b []byte) (int, error) { + w.t.Helper() + w.t.Logf("%s", string(b)) + return len(b), nil +} + +func CatchLogForTest(t testing.TB) { + prevWriter := log.Writer() + prevFlags := log.Flags() + t.Cleanup(func() { + log.SetOutput(prevWriter) + log.SetFlags(prevFlags) + }) + + log.SetOutput(&testLogWriter{t}) + log.SetFlags(prevFlags | log.Lshortfile) +} diff --git a/transient_data_test.go b/transient_data_test.go index 41ca971..2f856cc 100644 --- a/transient_data_test.go +++ b/transient_data_test.go @@ -133,6 +133,8 @@ func Test_TransientData(t *testing.T) { } func Test_TransientMessages(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) diff --git a/virtualsession_test.go b/virtualsession_test.go index 76673f9..27f126f 100644 --- a/virtualsession_test.go +++ b/virtualsession_test.go @@ -30,6 +30,8 @@ import ( ) func TestVirtualSession(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) roomId := "the-room-id" @@ -338,6 +340,8 @@ func checkHasEntryWithInCall(message *RoomEventServerMessage, sessionId string, } func TestVirtualSessionCustomInCall(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) roomId := "the-room-id" @@ -569,6 +573,8 @@ func TestVirtualSessionCustomInCall(t *testing.T) { } func TestVirtualSessionCleanup(t *testing.T) { + t.Parallel() + CatchLogForTest(t) hub, _, _, server := CreateHubForTest(t) roomId := "the-room-id"