diff --git a/pkg/share/manager/jsoncs3/jsoncs3.go b/pkg/share/manager/jsoncs3/jsoncs3.go index 021b541bd9..2e90b062ea 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3.go +++ b/pkg/share/manager/jsoncs3/jsoncs3.go @@ -340,6 +340,12 @@ func (m *Manager) initialize(ctx context.Context) error { return nil } +// Ready returns a channel that is closed once the background initialization +// goroutine has successfully connected to the metadata storage. +func (m *Manager) Ready() <-chan struct{} { + return m.ready +} + // waitForInit blocks until the background initialization goroutine has // successfully completed, or until ctx is cancelled. func (m *Manager) waitForInit(ctx context.Context) error { diff --git a/pkg/share/manager/jsoncs3/jsoncs3_test.go b/pkg/share/manager/jsoncs3/jsoncs3_test.go index 4620a69d26..fbb4563a49 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3_test.go +++ b/pkg/share/manager/jsoncs3/jsoncs3_test.go @@ -1163,7 +1163,13 @@ var _ = Describe("CleanupStaleShares", func() { m, err := jsoncs3.New(storage, nil, nil, 0, nil, 0) Expect(err).ToNot(HaveOccurred()) - ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) + // New initializes the metadata storage in the background. Wait for that + // to finish, otherwise the context below can expire while the manager is + // still initializing and CleanupStaleShares reports that instead of the + // migration timeout. + Eventually(m.Ready(), 10*time.Second).Should(BeClosed()) + + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() err = m.CleanupStaleShares(ctx)