From f1e9d27fe4f7f3b55d1b96a61067f4b226a37248 Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Fri, 27 Sep 2024 11:48:12 -0700 Subject: [PATCH] #5412: add unit test to assert caller ctx cancellation outcome --- ingest/cdp/producer_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ingest/cdp/producer_test.go b/ingest/cdp/producer_test.go index 1b0dfa98f4..eec0d77ecc 100644 --- a/ingest/cdp/producer_test.go +++ b/ingest/cdp/producer_test.go @@ -160,7 +160,7 @@ func TestBSBProducerFnGetLedgerError(t *testing.T) { DataStoreConfig: datastore.DataStoreConfig{}, BufferedStorageConfig: DefaultBufferedStorageBackendConfig(1), } - // we don't want to wait for retries, forece the first error to propagate + // we don't want to wait for retries, force the first error to propagate pubConfig.BufferedStorageConfig.RetryLimit = 0 mockDataStore := new(datastore.MockDataStore) mockDataStore.On("GetSchema").Return(datastore.DataStoreSchema{ @@ -183,6 +183,28 @@ func TestBSBProducerFnGetLedgerError(t *testing.T) { "error getting ledger") } +func TestBSBProducerCallerCancelsCtx(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + pubConfig := PublisherConfig{ + DataStoreConfig: datastore.DataStoreConfig{}, + BufferedStorageConfig: DefaultBufferedStorageBackendConfig(1), + } + mockDataStore := createMockdataStore(t, 2, 3, 64000) + + appCallback := func(lcm xdr.LedgerCloseMeta) error { + return nil + } + + cancel() + + datastoreFactory = func(_ context.Context, _ datastore.DataStoreConfig) (datastore.DataStore, error) { + return mockDataStore, nil + } + assert.ErrorIs(t, + PublishFromBufferedStorageBackend(ledgerbackend.BoundedRange(uint32(2), uint32(3)), pubConfig, ctx, appCallback), + context.Canceled) +} + func TestBSBProducerFnCallbackError(t *testing.T) { ctx := context.Background() pubConfig := PublisherConfig{