Skip to content

Commit

Permalink
#5412: add unit test to assert caller ctx cancellation outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Sep 27, 2024
1 parent 8c3f694 commit f1e9d27
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ingest/cdp/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down

0 comments on commit f1e9d27

Please sign in to comment.