@@ -2650,8 +2650,8 @@ func TestReinit(t *testing.T) {
2650
2650
2651
2651
db , ps := dbtestutil .NewDB (t )
2652
2652
pubsubSpy := pubsubReinitSpy {
2653
- Pubsub : ps ,
2654
- subscribed : make (chan string ),
2653
+ Pubsub : ps ,
2654
+ triedToSubscribe : make (chan string ),
2655
2655
}
2656
2656
client := coderdtest .New (t , & coderdtest.Options {
2657
2657
Database : db ,
@@ -2664,9 +2664,9 @@ func TestReinit(t *testing.T) {
2664
2664
OwnerID : user .UserID ,
2665
2665
}).WithAgent ().Do ()
2666
2666
2667
- pubsubSpy .Mutex . Lock ()
2667
+ pubsubSpy .Lock ()
2668
2668
pubsubSpy .expectedEvent = agentsdk .PrebuildClaimedChannel (r .Workspace .ID )
2669
- pubsubSpy .Mutex . Unlock ()
2669
+ pubsubSpy .Unlock ()
2670
2670
2671
2671
agentCtx := testutil .Context (t , testutil .WaitShort )
2672
2672
agentClient := agentsdk .New (client .URL )
@@ -2681,7 +2681,7 @@ func TestReinit(t *testing.T) {
2681
2681
2682
2682
// We need to subscribe before we publish, lest we miss the event
2683
2683
ctx := testutil .Context (t , testutil .WaitShort )
2684
- testutil .TryReceive (ctx , t , pubsubSpy .subscribed ) // Wait for the appropriate subscription
2684
+ testutil .TryReceive (ctx , t , pubsubSpy .triedToSubscribe )
2685
2685
2686
2686
// Now that we're subscribed, publish the event
2687
2687
err := prebuilds .NewPubsubWorkspaceClaimPublisher (ps ).PublishWorkspaceClaim (agentsdk.ReinitializationEvent {
@@ -2699,15 +2699,16 @@ func TestReinit(t *testing.T) {
2699
2699
type pubsubReinitSpy struct {
2700
2700
pubsub.Pubsub
2701
2701
sync.Mutex
2702
- subscribed chan string
2703
- expectedEvent string
2702
+ triedToSubscribe chan string
2703
+ expectedEvent string
2704
2704
}
2705
2705
2706
2706
func (p * pubsubReinitSpy ) Subscribe (event string , listener pubsub.Listener ) (cancel func (), err error ) {
2707
+ cancel , err = p .Pubsub .Subscribe (event , listener )
2707
2708
p .Lock ()
2708
2709
if p .expectedEvent != "" && event == p .expectedEvent {
2709
- close (p .subscribed )
2710
+ close (p .triedToSubscribe )
2710
2711
}
2711
2712
p .Unlock ()
2712
- return p . Pubsub . Subscribe ( event , listener )
2713
+ return cancel , err
2713
2714
}
0 commit comments