github.com/Jeffail/benthos/v3@v3.65.0/lib/test/integration/nats_stream_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/Jeffail/benthos/v3/internal/integration"
     9  	"github.com/nats-io/stan.go"
    10  	"github.com/ory/dockertest/v3"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  var _ = registerIntegrationTest("nats_stream", func(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	pool, err := dockertest.NewPool("")
    19  	require.NoError(t, err)
    20  
    21  	pool.MaxWait = time.Second * 30
    22  	resource, err := pool.Run("nats-streaming", "latest", nil)
    23  	require.NoError(t, err)
    24  	t.Cleanup(func() {
    25  		assert.NoError(t, pool.Purge(resource))
    26  	})
    27  
    28  	resource.Expire(900)
    29  	require.NoError(t, pool.Retry(func() error {
    30  		natsConn, err := stan.Connect(
    31  			"test-cluster", "benthos_test_client",
    32  			stan.NatsURL(fmt.Sprintf("tcp://localhost:%v", resource.GetPort("4222/tcp"))),
    33  		)
    34  		if err != nil {
    35  			return err
    36  		}
    37  		natsConn.Close()
    38  		return nil
    39  	}))
    40  
    41  	template := `
    42  output:
    43    nats_stream:
    44      urls: [ nats://localhost:$PORT ]
    45      cluster_id: test-cluster
    46      client_id: client-output-$ID
    47      subject: subject-$ID
    48      max_in_flight: $MAX_IN_FLIGHT
    49  
    50  input:
    51    nats_stream:
    52      urls: [ nats://localhost:$PORT ]
    53      cluster_id: test-cluster
    54      client_id: client-input-$ID
    55      queue: queue-$ID
    56      subject: subject-$ID
    57      ack_wait: 5s
    58  `
    59  	suite := integration.StreamTests(
    60  		integration.StreamTestOpenClose(),
    61  		// integration.StreamTestMetadata(), TODO
    62  		integration.StreamTestSendBatch(10),
    63  		integration.StreamTestStreamParallel(1000),
    64  		integration.StreamTestStreamSequential(1000),
    65  		integration.StreamTestStreamParallelLossy(1000),
    66  		integration.StreamTestStreamParallelLossyThroughReconnect(1000),
    67  	)
    68  	suite.Run(
    69  		t, template,
    70  		integration.StreamTestOptSleepAfterInput(100*time.Millisecond),
    71  		integration.StreamTestOptSleepAfterOutput(100*time.Millisecond),
    72  		integration.StreamTestOptPort(resource.GetPort("4222/tcp")),
    73  	)
    74  	t.Run("with max in flight", func(t *testing.T) {
    75  		t.Parallel()
    76  		suite.Run(
    77  			t, template,
    78  			integration.StreamTestOptSleepAfterInput(100*time.Millisecond),
    79  			integration.StreamTestOptSleepAfterOutput(100*time.Millisecond),
    80  			integration.StreamTestOptPort(resource.GetPort("4222/tcp")),
    81  			integration.StreamTestOptMaxInFlight(10),
    82  		)
    83  	})
    84  })