From 295fee04efa712f89b71002dada2f44515ec72e9 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 17 Nov 2022 18:23:09 +0300 Subject: [PATCH] make WaitCatchUp public in DASer --- das/daser.go | 5 +++++ das/daser_test.go | 12 ++++++++++-- das/state.go | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/das/daser.go b/das/daser.go index 92859ed9f7..ce4b41225e 100644 --- a/das/daser.go +++ b/das/daser.go @@ -169,3 +169,8 @@ func (d *DASer) sample(ctx context.Context, h *header.ExtendedHeader) error { func (d *DASer) SamplingStats(ctx context.Context) (SamplingStats, error) { return d.sampler.stats(ctx) } + +// WaitCatchUp waits for DASer to indicate catchup is done +func (d *DASer) WaitCatchUp(ctx context.Context) error { + return d.sampler.state.waitCatchUp(ctx) +} diff --git a/das/daser_test.go b/das/daser_test.go index ca4b244b72..ae43d28fbb 100644 --- a/das/daser_test.go +++ b/das/daser_test.go @@ -54,12 +54,17 @@ func TestDASerLifecycle(t *testing.T) { // ensure checkpoint is stored at 30 assert.EqualValues(t, 30, checkpoint.SampleFrom-1) }() - // wait for dasing catch-up routine to indicateDone + + // wait for mock to indicate that catchup is done select { case <-ctx.Done(): t.Fatal(ctx.Err()) case <-mockGet.doneCh: } + + // wait for DASer to indicate done + assert.NoError(t, daser.WaitCatchUp(ctx)) + // give catch-up routine a second to finish up sampling last header assert.NoError(t, daser.sampler.state.waitCatchUp(ctx)) } @@ -80,13 +85,16 @@ func TestDASer_Restart(t *testing.T) { err = daser.Start(ctx) require.NoError(t, err) - // wait for dasing catch-up routine to indicateDone + // wait for mock to indicate that catchup is done select { case <-ctx.Done(): t.Fatal(ctx.Err()) case <-mockGet.doneCh: } + // wait for DASer to indicate done + assert.NoError(t, daser.WaitCatchUp(ctx)) + err = daser.Stop(ctx) require.NoError(t, err) diff --git a/das/state.go b/das/state.go index 1f96560dc9..970433b8bc 100644 --- a/das/state.go +++ b/das/state.go @@ -221,7 +221,7 @@ func (s *coordinatorState) checkDone() { } } -// waitCatchUp waits for sampling process to indicateDone catchup +// waitCatchUp waits for sampling process to indicate catchup is done func (s *coordinatorState) waitCatchUp(ctx context.Context) error { select { case <-s.catchUpDoneCh: