github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/events/finalization_actor_test.go (about) 1 package events 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/onflow/flow-go/consensus/hotstuff/model" 9 "github.com/onflow/flow-go/module/irrecoverable" 10 "github.com/onflow/flow-go/utils/unittest" 11 ) 12 13 // TestFinalizationActor_SubscribeDuringConstruction tests that the FinalizationActor 14 // subscribes to the provided distributor at construction and can subsequently receive notifications. 15 func TestFinalizationActor_SubscribeDuringConstruction(t *testing.T) { 16 17 // to ensure the actor is subscribed, create and start the worker, then register the callback 18 done := make(chan struct{}) 19 actor, worker := NewFinalizationActor(func(_ *model.Block) error { 20 close(done) 21 return nil 22 }) 23 ctx, cancel := irrecoverable.NewMockSignalerContextWithCancel(t, context.Background()) 24 defer cancel() 25 go worker(ctx, func() {}) 26 actor.OnFinalizedBlock(nil) 27 28 unittest.AssertClosesBefore(t, done, time.Second) 29 }