forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log tx meta when ingestion failures occur (stellar#5268)
- Loading branch information
Showing
5 changed files
with
146 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
services/horizon/internal/ingest/change_processors_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package ingest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/stellar/go/ingest" | ||
"github.com/stellar/go/services/horizon/internal/ingest/processors" | ||
"github.com/stellar/go/support/errors" | ||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
func TestStreamReaderError(t *testing.T) { | ||
tt := assert.New(t) | ||
ctx := context.Background() | ||
|
||
mockChangeReader := &ingest.MockChangeReader{} | ||
mockChangeReader. | ||
On("Read"). | ||
Return(ingest.Change{}, errors.New("transient error")).Once() | ||
mockChangeProcessor := &processors.MockChangeProcessor{} | ||
|
||
err := streamChanges(ctx, mockChangeProcessor, 1, mockChangeReader) | ||
tt.EqualError(err, "could not read transaction: transient error") | ||
} | ||
|
||
func TestStreamChangeProcessorError(t *testing.T) { | ||
tt := assert.New(t) | ||
ctx := context.Background() | ||
|
||
change := ingest.Change{ | ||
Type: xdr.LedgerEntryTypeAccount, | ||
Pre: &xdr.LedgerEntry{ | ||
LastModifiedLedgerSeq: 10, | ||
Data: xdr.LedgerEntryData{ | ||
Type: xdr.LedgerEntryTypeAccount, | ||
Account: &xdr.AccountEntry{ | ||
AccountId: xdr.MustAddress("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"), | ||
}, | ||
}, | ||
}, | ||
Post: &xdr.LedgerEntry{ | ||
LastModifiedLedgerSeq: 11, | ||
Data: xdr.LedgerEntryData{ | ||
Type: xdr.LedgerEntryTypeAccount, | ||
Account: &xdr.AccountEntry{ | ||
AccountId: xdr.MustAddress("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"), | ||
Balance: 200, | ||
}, | ||
}, | ||
}, | ||
} | ||
mockChangeReader := &ingest.MockChangeReader{} | ||
mockChangeReader. | ||
On("Read"). | ||
Return(change, nil).Once() | ||
|
||
mockChangeProcessor := &processors.MockChangeProcessor{} | ||
mockChangeProcessor. | ||
On( | ||
"ProcessChange", ctx, | ||
change, | ||
). | ||
Return(errors.New("transient error")).Once() | ||
|
||
logsGet := log.StartTest(logrus.ErrorLevel) | ||
err := streamChanges(ctx, mockChangeProcessor, 1, mockChangeReader) | ||
tt.EqualError(err, "could not process change: transient error") | ||
logs := logsGet() | ||
line, err := logs[0].String() | ||
tt.NoError(err) | ||
|
||
preB64, err := xdr.MarshalBase64(change.Pre) | ||
tt.NoError(err) | ||
postB64, err := xdr.MarshalBase64(change.Post) | ||
tt.NoError(err) | ||
expectedTokens := []string{"LedgerEntryTypeAccount", preB64, postB64} | ||
|
||
for _, token := range expectedTokens { | ||
tt.Contains(line, token) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
services/horizon/internal/ingest/processors/change_processors.go
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
services/horizon/internal/ingest/processors/change_processors_test.go
This file was deleted.
Oops, something went wrong.