From 71d3e6f241499117f86d76782f39da852a417397 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Thu, 12 Dec 2024 16:11:26 +0100 Subject: [PATCH] Add a test that Configure is called in sequence --- pkg/x/muxer/muxer_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/x/muxer/muxer_test.go b/pkg/x/muxer/muxer_test.go index e6c2bb60fd..b706b04146 100644 --- a/pkg/x/muxer/muxer_test.go +++ b/pkg/x/muxer/muxer_test.go @@ -17,6 +17,7 @@ package muxer import ( "context" "fmt" + "sync/atomic" "testing" "github.com/pulumi/pulumi/sdk/v3/go/common/diag" @@ -200,3 +201,37 @@ func (s diffConfigServer) DiffConfig( } return s.UnimplementedResourceProviderServer.DiffConfig(ctx, req) } + +func TestConfigureInSequence(t *testing.T) { + t.Parallel() + ctx := context.Background() + + for i := 0; i < 1000; i++ { + var count atomic.Uint32 + m := &muxer{ + host: &host{}, + servers: []server{ + configure{t: t, expect: 0, counter: &count}, + configure{t: t, expect: 1, counter: &count}, + configure{t: t, expect: 2, counter: &count}, + configure{t: t, expect: 3, counter: &count}, + }, + } + _, err := m.Configure(ctx, &pulumirpc.ConfigureRequest{}) + require.NoError(t, err) + + assert.Equal(t, uint32(4), count.Load()) + } +} + +type configure struct { + pulumirpc.UnimplementedResourceProviderServer + t *testing.T + expect uint32 + counter *atomic.Uint32 +} + +func (c configure) Configure(context.Context, *pulumirpc.ConfigureRequest) (*pulumirpc.ConfigureResponse, error) { + assert.True(c.t, c.counter.CompareAndSwap(c.expect, c.expect+1), "") + return &pulumirpc.ConfigureResponse{}, nil +}