github.com/cilium/cilium@v1.16.2/clustermesh-apiserver/syncstate/syncstate_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package syncstate 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 "github.com/cilium/cilium/pkg/clustermesh/types" 13 ) 14 15 func TestSyncState(t *testing.T) { 16 var doneFuncs []func(context.Context) 17 ss := new(MetricsProvider(), types.ClusterInfo{Name: "test"}) 18 19 // add several resource to the SyncState 20 for i := 0; i < 3; i++ { 21 doneFuncs = append(doneFuncs, ss.WaitForResource()) 22 } 23 ss.Stop() 24 25 // call all doneFuncs to simulate the resources being synchronized 26 for _, f := range doneFuncs { 27 // ensure that SyncState is not complete until all doneFuncs are called 28 require.False(t, ss.Complete()) 29 f(context.Background()) 30 } 31 32 require.True(t, ss.Complete()) 33 }