mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* chore: golangci: add linter rule to report usage of t.FailNow inside goroutines * chore: avoid t.FailNow in goroutines to appease the race detector
36 lines
740 B
Go
36 lines
740 B
Go
package database_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd/database"
|
|
)
|
|
|
|
func TestPubsubMemory(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("Memory", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
pubsub := database.NewPubsubInMemory()
|
|
event := "test"
|
|
data := "testing"
|
|
messageChannel := make(chan []byte)
|
|
cancelFunc, err := pubsub.Subscribe(event, func(ctx context.Context, message []byte) {
|
|
messageChannel <- message
|
|
})
|
|
require.NoError(t, err)
|
|
defer cancelFunc()
|
|
go func() {
|
|
err = pubsub.Publish(event, []byte(data))
|
|
assert.NoError(t, err)
|
|
}()
|
|
message := <-messageChannel
|
|
assert.Equal(t, string(message), data)
|
|
})
|
|
}
|