Przeglądaj źródła

fix flaky unit tests

The server unit tests would occasionally hang because of a race condition
where the client puts a message on msgCh and closes the connection before
dispatchIncomingMessages starts the main loop, which sometimes hits
the error channel first and closes the method early before the handler
can run and close the wait group.
Mike 5 miesięcy temu
rodzic
commit
1dd0a0b052
1 zmienionych plików z 4 dodań i 4 usunięć
  1. 4 4
      server/oscar/server_test.go

+ 4 - 4
server/oscar/server_test.go

@@ -358,7 +358,6 @@ func TestOscarServer_RouteConnection_BOS(t *testing.T) {
 			SubGroup:  wire.OServiceClientOnline,
 		}
 		assert.NoError(t, flapc.SendSNAC(frame, struct{}{}))
-		assert.NoError(t, clientConn.Close())
 	}()
 
 	wg := &sync.WaitGroup{}
@@ -409,6 +408,7 @@ func TestOscarServer_RouteConnection_BOS(t *testing.T) {
 	wg.Add(2)
 	handler := func(ctx context.Context, serverType uint16, instance *state.SessionInstance, inFrame wire.SNACFrame, r io.Reader, rw ResponseWriter, listener config.Listener) error {
 		defer wg.Done()
+		assert.NoError(t, clientConn.Close())
 		return nil
 	}
 
@@ -482,7 +482,6 @@ func TestOscarServer_RouteConnection_BOS_MultiSessionSignoff(t *testing.T) {
 			SubGroup:  wire.OServiceClientOnline,
 		}
 		assert.NoError(t, flapc.SendSNAC(frame, struct{}{}))
-		assert.NoError(t, clientConn.Close())
 	}()
 
 	wg := &sync.WaitGroup{}
@@ -522,6 +521,7 @@ func TestOscarServer_RouteConnection_BOS_MultiSessionSignoff(t *testing.T) {
 	wg.Add(2)
 	handler := func(ctx context.Context, serverType uint16, instance *state.SessionInstance, inFrame wire.SNACFrame, r io.Reader, rw ResponseWriter, listener config.Listener) error {
 		defer wg.Done()
+		assert.NoError(t, clientConn.Close())
 		return nil
 	}
 
@@ -654,7 +654,6 @@ func TestOscarServer_RouteConnection_Chat(t *testing.T) {
 			SubGroup:  wire.OServiceClientOnline,
 		}
 		assert.NoError(t, flapc.SendSNAC(frame, struct{}{}))
-		assert.NoError(t, clientConn.Close())
 	}()
 
 	wg := &sync.WaitGroup{}
@@ -692,6 +691,7 @@ func TestOscarServer_RouteConnection_Chat(t *testing.T) {
 	wg.Add(1)
 	handler := func(ctx context.Context, serverType uint16, instance *state.SessionInstance, inFrame wire.SNACFrame, r io.Reader, rw ResponseWriter, listener config.Listener) error {
 		defer wg.Done()
+		assert.NoError(t, clientConn.Close())
 		return nil
 	}
 
@@ -756,7 +756,6 @@ func TestOscarServer_RouteConnection_Admin(t *testing.T) {
 			SubGroup:  wire.OServiceClientOnline,
 		}
 		assert.NoError(t, flapc.SendSNAC(frame, struct{}{}))
-		assert.NoError(t, clientConn.Close())
 	}()
 
 	wg := &sync.WaitGroup{}
@@ -787,6 +786,7 @@ func TestOscarServer_RouteConnection_Admin(t *testing.T) {
 	wg.Add(1)
 	handler := func(ctx context.Context, serverType uint16, instance *state.SessionInstance, inFrame wire.SNACFrame, r io.Reader, rw ResponseWriter, listener config.Listener) error {
 		defer wg.Done()
+		assert.NoError(t, clientConn.Close())
 		return nil
 	}