...

Source file src/github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest/events.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest

     1  package sharedtest
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/launchdarkly/go-server-sdk/v6/interfaces"
     8  
     9  	th "github.com/launchdarkly/go-test-helpers/v3"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  // ExpectFlagChangeEvents asserts that a channel receives flag change events for the specified keys (in
    15  // any order) and then does not receive any more events for the next 100ms.
    16  func ExpectFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent, keys ...string) {
    17  	expectedChangedFlagKeys := make(map[string]bool)
    18  	for _, key := range keys {
    19  		expectedChangedFlagKeys[key] = true
    20  	}
    21  	actualChangedFlagKeys := make(map[string]bool)
    22  ReadLoop:
    23  	for i := 0; i < len(keys); i++ {
    24  		select {
    25  		case event, ok := <-ch:
    26  			if !ok {
    27  				break ReadLoop
    28  			}
    29  			actualChangedFlagKeys[event.Key] = true
    30  		case <-time.After(time.Second):
    31  			assert.Fail(t, "did not receive expected event", "expected: %v, received: %v",
    32  				expectedChangedFlagKeys, actualChangedFlagKeys)
    33  			return
    34  		}
    35  	}
    36  	assert.Equal(t, expectedChangedFlagKeys, actualChangedFlagKeys)
    37  	th.AssertNoMoreValues(t, ch, time.Millisecond*100)
    38  }
    39  

View as plain text