Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5afa765

Browse files
author
sspaink
committed
remove sleeping by removing the need for the loop
Signed-off-by: sspaink <[email protected]>
1 parent 3489e27 commit 5afa765

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

v1/plugins/status/plugin_test.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func TestPluginNoLogging(t *testing.T) {
440440
}
441441
}
442442

443-
func TestPluginStartTriggerManual(t *testing.T) {
443+
func TestPluginStartTriggerManualStart(t *testing.T) {
444444

445445
fixture := newTestFixture(t, nil)
446446
fixture.server.ch = make(chan UpdateRequestV1)
@@ -476,22 +476,45 @@ func TestPluginStartTriggerManual(t *testing.T) {
476476
if !maps.Equal(result.Labels, exp.Labels) {
477477
t.Fatalf("Expected: %v but got: %v", exp, result)
478478
}
479+
}
480+
481+
func TestPluginStartTriggerManual(t *testing.T) {
482+
fixture := newTestFixture(t, nil)
483+
fixture.server.ch = make(chan UpdateRequestV1)
484+
defer fixture.server.stop()
485+
tr := plugins.TriggerManual
486+
fixture.plugin.config.Trigger = &tr
479487

480488
status := testStatus()
481489

482490
fixture.plugin.BulkUpdateBundleStatus(map[string]*bundle.Status{"test": status})
483491

484-
// make sure the lastBundleStatuses has been written so the trigger sends the expected status
485-
// otherwise there could be a race condition before the bundle status is written
486-
time.Sleep(10 * time.Millisecond)
492+
statuses := <-fixture.plugin.bulkBundleCh
493+
fixture.plugin.lastBundleStatuses = statuses
487494

488495
// trigger the status update
489496
go func() {
490-
_ = fixture.plugin.Trigger(ctx)
497+
_ = fixture.plugin.Trigger(context.Background())
491498
}()
492499

493-
result = <-fixture.server.ch
500+
go func() {
501+
update := <-fixture.plugin.trigger
502+
err := fixture.plugin.oneShot(update.ctx)
503+
if err != nil {
504+
t.Error(err)
505+
return
506+
}
507+
}()
508+
509+
result := <-fixture.server.ch
494510

511+
exp := UpdateRequestV1{
512+
Labels: map[string]string{
513+
"id": "test-instance-id",
514+
"app": "example-app",
515+
"version": version.Version,
516+
},
517+
}
495518
exp.Bundles = map[string]*bundle.Status{"test": status}
496519

497520
if !maps.EqualFunc(result.Bundles, exp.Bundles, (*bundle.Status).Equal) {

0 commit comments

Comments
 (0)