-
Notifications
You must be signed in to change notification settings - Fork 6
Add goroutine leak detection tests to Relayer, TXM, and LogPoller services #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ogtownsend
wants to merge
12
commits into
main
Choose a base branch
from
ogt/add-leak-detection-test-to-services
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
18b947b
Add goroutine leak detection test to main services
ogtownsend 55e24b7
define sleeps to be in terms of the tick periods
ogtownsend 7cec7eb
nix hash
ogtownsend 40f1c92
decode hex
ogtownsend 7a3ecc6
update go version for nix
ogtownsend e551a71
lint and tidy
ogtownsend e009d80
nix tidy
ogtownsend 8baa721
lint
ogtownsend b1c13d0
lint
ogtownsend 953cd9c
undo newline removal
ogtownsend 3aa187f
Merge remote-tracking branch 'origin/main' into ogt/add-leak-detectio…
ogtownsend d340f36
nix things..??
ogtownsend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -54,3 +54,6 @@ cmd/chainlink-ton/chainlink-ton | |
|
|
||
| # Experimental files | ||
| pkg/ton/codec/jsoncodec/ | ||
|
|
||
| # Agents | ||
| .cursor/ | ||
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,109 @@ | ||
| package logpoller | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/xssnick/tonutils-go/address" | ||
| "github.com/xssnick/tonutils-go/tl" | ||
| "github.com/xssnick/tonutils-go/tlb" | ||
| "github.com/xssnick/tonutils-go/ton" | ||
|
|
||
| commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-ton/pkg/logpoller/models" | ||
| ) | ||
|
|
||
| // TestLogPollerServiceLeak runs the real engine ticks, polling loop, pruning ticker, and loader goroutines | ||
| // under goleak. After Start, it exercises filter management (Register/Has/Unregister) and Replay so the | ||
| // public service surface runs real code beyond Start/Close. | ||
| func TestLogPollerServiceLeak(t *testing.T) { | ||
| tests.VerifyNoLeaks(t) | ||
|
|
||
| lggr := logger.Test(t) | ||
| chainID := "leak-lp" | ||
| ctx := context.Background() | ||
|
|
||
| cfg := DefaultConfigSet | ||
| cfg.PollPeriod = commonconfig.MustNewDuration(100 * time.Millisecond) | ||
| cfg.PruningInterval = commonconfig.MustNewDuration(1 * time.Minute) | ||
| cfg.PruningStartDelay = commonconfig.MustNewDuration(0) | ||
| cfg.MCBlockResolveMaxRetries = 1 | ||
| cfg.MCBlockResolveBaseDelay = commonconfig.MustNewDuration(time.Millisecond) | ||
| cfg.ApplyDefaults() | ||
| require.NoError(t, cfg.ValidateConfig()) | ||
|
|
||
| poll := cfg.PollPeriod.Duration() | ||
|
|
||
| currentMC := &ton.BlockIDExt{Workchain: address.MasterchainID, SeqNo: 100, Shard: 1} | ||
| lite := &mockLiteClient{ | ||
| queryFunc: func(_ context.Context, _ tl.Serializable, resp tl.Serializable) error { | ||
| ptr := resp.(*tl.Serializable) | ||
| *ptr = ton.ShardBlockProof{ | ||
| MasterchainID: &ton.BlockIDExt{Workchain: address.MasterchainID, SeqNo: 50}, | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
| mockClient := &mockAPIClient{ | ||
| masterchainInfo: currentMC, | ||
| lookupBlockFunc: func(seqNo uint32) *ton.BlockIDExt { | ||
| return &ton.BlockIDExt{Workchain: address.MasterchainID, SeqNo: seqNo, Shard: 1} | ||
| }, | ||
| liteClient: lite, | ||
| } | ||
|
|
||
| opts := &ServiceOptions{ | ||
| Config: cfg, | ||
| FilterStore: newMockFilterStore(), | ||
| TxLoader: &testTxLoader{}, // empty stream; still exercises per-address goroutines in loadTxsForAddresses | ||
| LogStore: &testLogStore{}, | ||
| } | ||
|
ogtownsend marked this conversation as resolved.
|
||
|
|
||
| clientProvider := func(context.Context) (ton.APIClientWrapped, error) { | ||
| return mockClient, nil | ||
| } | ||
|
|
||
| svc, err := NewService(lggr, chainID, clientProvider, opts) | ||
| require.NoError(t, err) | ||
|
|
||
| addr := testAddress(t) | ||
| _, err = svc.RegisterFilter(ctx, models.Filter{ | ||
| Name: "leak-filter", | ||
| Address: addr, | ||
| MsgType: tlb.MsgTypeExternalOut, | ||
| EventSig: 0xcafebabe, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| servicetest.RunHealthy(t, svc) | ||
|
|
||
| // Wait several poll periods so processBlockRange runs at least once (fans out per-address | ||
| // loader goroutines and the resolveTxsMCBlock goroutine). | ||
| time.Sleep(3 * poll) | ||
|
|
||
| // Exercise additional public service methods while the engine is running. | ||
| exists, err := svc.HasFilter(ctx, "leak-filter") | ||
| require.NoError(t, err) | ||
| require.True(t, exists) | ||
|
|
||
| _, err = svc.RegisterFilter(ctx, models.Filter{ | ||
| Name: "leak-filter-2", | ||
| Address: testAddress2(t), | ||
| MsgType: tlb.MsgTypeExternalOut, | ||
| EventSig: 0xfeedface, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| require.NoError(t, svc.Replay(ctx, 50)) | ||
|
|
||
| require.NoError(t, svc.UnregisterFilter(ctx, "leak-filter")) | ||
|
|
||
| // Give the poller time for more ticks after filter and replay mutations. | ||
| time.Sleep(2 * poll) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.