@@ -340,32 +340,26 @@ func TestSubscribe(t *testing.T) {
340
340
341
341
mockServer := newMockSubscribeServer (ctx )
342
342
343
- // put the requests on the listenCh for the Subscription loop to pick up
343
+ // Define the broadcast messages to be sent later
344
344
loopFile := & pb.File {
345
345
FileMeta : & pb.FileMeta {
346
346
Name : "some-other.conf" ,
347
347
Hash : "56789" ,
348
348
},
349
349
}
350
- listenCh <- broadcast.NginxAgentMessage {
351
- Type : broadcast .ConfigApplyRequest ,
352
- FileOverviews : []* pb.File {loopFile },
353
- }
354
-
355
350
loopAction := & pb.NGINXPlusAction {
356
351
Action : & pb.NGINXPlusAction_UpdateStreamServers {},
357
352
}
358
- listenCh <- broadcast.NginxAgentMessage {
359
- Type : broadcast .APIRequest ,
360
- NGINXPlusAction : loopAction ,
361
- }
362
353
363
354
// start the Subscriber
364
355
errCh := make (chan error )
365
356
go func () {
366
357
errCh <- cs .Subscribe (mockServer )
367
358
}()
368
359
360
+ // PHASE 1: Initial config is sent by setInitialConfig() BEFORE the event loop starts
361
+ // These should NOT signal ResponseCh as they're not broadcast operations
362
+
369
363
// ensure that the initial config file was sent when the Subscription connected
370
364
expFile := & pb.File {
371
365
FileMeta : & pb.FileMeta {
@@ -374,6 +368,7 @@ func TestSubscribe(t *testing.T) {
374
368
},
375
369
}
376
370
ensureFileWasSent (g , mockServer , expFile )
371
+ // Respond to initial config - this should NOT signal ResponseCh
377
372
mockServer .recvChan <- & pb.DataPlaneResponse {
378
373
CommandResponse : & pb.CommandResponse {
379
374
Status : pb .CommandResponse_COMMAND_STATUS_OK ,
@@ -382,22 +377,40 @@ func TestSubscribe(t *testing.T) {
382
377
383
378
// ensure that the initial API request was sent when the Subscription connected
384
379
ensureAPIRequestWasSent (g , mockServer , initialAction )
380
+ // Respond to initial API request - this should NOT signal ResponseCh
385
381
mockServer .recvChan <- & pb.DataPlaneResponse {
386
382
CommandResponse : & pb.CommandResponse {
387
383
Status : pb .CommandResponse_COMMAND_STATUS_OK ,
388
384
},
389
385
}
390
386
387
+ // Wait for status queue to be updated after initial config completes
391
388
g .Eventually (func () string {
392
389
obj := cs .statusQueue .Dequeue (ctx )
393
390
return obj .Deployment .Name
394
391
}).Should (Equal ("nginx-deployment" ))
395
392
396
- // ensure the second file was sent in the loop
393
+ // PHASE 2: Now send broadcast operations to the event loop
394
+ // Put the broadcast requests on the listenCh for the Subscription loop to pick up
395
+ listenCh <- broadcast.NginxAgentMessage {
396
+ Type : broadcast .ConfigApplyRequest ,
397
+ FileOverviews : []* pb.File {loopFile },
398
+ }
399
+
400
+ // PHASE 2: Broadcast operations from the event loop
401
+ // These SHOULD signal ResponseCh as they are broadcast operations
402
+
403
+ // ensure the broadcast file was sent in the loop
397
404
ensureFileWasSent (g , mockServer , loopFile )
398
405
verifyResponse (g , mockServer , responseCh )
399
406
400
- // ensure the second action was sent in the loop
407
+ // Send second broadcast operation
408
+ listenCh <- broadcast.NginxAgentMessage {
409
+ Type : broadcast .APIRequest ,
410
+ NGINXPlusAction : loopAction ,
411
+ }
412
+
413
+ // ensure the broadcast action was sent in the loop
401
414
ensureAPIRequestWasSent (g , mockServer , loopAction )
402
415
verifyResponse (g , mockServer , responseCh )
403
416
0 commit comments