github.com/kubeshop/testkube@v1.17.23/pkg/event/bus/testserver_test.go (about)

     1  package bus
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestServerRestart(t *testing.T) {
    11  	// given NATS server
    12  	s, nc := TestServerWithConnection()
    13  	defer s.Shutdown()
    14  
    15  	// and NATS Subscription
    16  	sub, err := nc.SubscribeSync("aaa")
    17  	assert.NoError(t, err)
    18  
    19  	// when data is published to NATS
    20  	go func() {
    21  		nc.Publish("aaa", []byte("hello"))
    22  	}()
    23  
    24  	// then we should be able to read it
    25  	msg, err := sub.NextMsg(100 * time.Millisecond)
    26  	assert.NoError(t, err)
    27  	assert.Equal(t, "hello", string(msg.Data))
    28  }