Skip to content

Commit

Permalink
Add a test that Configure is called in sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Dec 12, 2024
1 parent 19c794d commit 71d3e6f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/x/muxer/muxer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package muxer
import (
"context"
"fmt"
"sync/atomic"
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
Expand Down Expand Up @@ -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
}

0 comments on commit 71d3e6f

Please sign in to comment.