diff --git a/api4/channel_test.go b/api4/channel_test.go index f46c024e1a..bc419379ec 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -1714,27 +1714,19 @@ func TestConvertChannelToPrivate(t *testing.T) { CheckOKStatus(t, resp) require.Equal(t, model.CHANNEL_PRIVATE, rchannel.Type, "channel should be converted from public to private") - stop := make(chan bool) - eventHit := false + timeout := time.After(10 * time.Second) - go func() { - for { - select { - case resp := <-WebSocketClient.EventChannel: - if resp.EventType() == model.WEBSOCKET_EVENT_CHANNEL_CONVERTED && resp.GetData()["channel_id"].(string) == publicChannel2.Id { - eventHit = true - } - case <-stop: + for { + select { + case resp := <-WebSocketClient.EventChannel: + if resp.EventType() == model.WEBSOCKET_EVENT_CHANNEL_CONVERTED && resp.GetData()["channel_id"].(string) == publicChannel2.Id { return } + case <-timeout: + require.Fail(t, "timed out waiting for channel_converted event") + return } - }() - - time.Sleep(400 * time.Millisecond) - - stop <- true - - require.True(t, eventHit, "did not receive channel_converted event") + } } func TestUpdateChannelPrivacy(t *testing.T) {