Browse Source

context: cleaning up context dead ends (#7963)

pull/7974/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
2ffb262600
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 17 deletions
  1. +1
    -2
      cmd/tendermint/commands/light.go
  2. +1
    -1
      internal/rpc/core/events.go
  3. +1
    -1
      rpc/client/event_test.go
  4. +2
    -2
      rpc/client/helpers.go
  5. +1
    -1
      rpc/client/http/ws.go
  6. +2
    -2
      rpc/client/main_test.go
  7. +4
    -4
      rpc/client/rpc_test.go
  8. +1
    -1
      test/e2e/node/main.go
  9. +2
    -3
      test/e2e/runner/benchmark.go

+ 1
- 2
cmd/tendermint/commands/light.go View File

@ -1,7 +1,6 @@
package commands package commands
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
@ -149,7 +148,7 @@ for applications built w/ Cosmos SDK).
// Initiate the light client. If the trusted store already has blocks in it, this // Initiate the light client. If the trusted store already has blocks in it, this
// will be used else we use the trusted options. // will be used else we use the trusted options.
c, err := light.NewHTTPClient( c, err := light.NewHTTPClient(
context.Background(),
cmd.Context(),
chainID, chainID,
light.TrustOptions{ light.TrustOptions{
Period: trustingPeriod, Period: trustingPeriod,


+ 1
- 1
internal/rpc/core/events.go View File

@ -57,7 +57,7 @@ func (env *Environment) Subscribe(ctx context.Context, query string) (*coretypes
// Capture the current ID, since it can change in the future. // Capture the current ID, since it can change in the future.
subscriptionID := callInfo.RPCRequest.ID subscriptionID := callInfo.RPCRequest.ID
go func() { go func() {
opctx, opcancel := context.WithCancel(context.Background())
opctx, opcancel := context.WithCancel(context.TODO())
defer opcancel() defer opcancel()
for { for {


+ 1
- 1
rpc/client/event_test.go View File

@ -51,7 +51,7 @@ func testTxEventsSent(ctx context.Context, t *testing.T, broadcastMethod string,
}() }()
// and wait for confirmation // and wait for confirmation
evt, err := client.WaitForOneEvent(c, types.EventTxValue, waitForEventTimeout)
evt, err := client.WaitForOneEvent(ctx, c, types.EventTxValue, waitForEventTimeout)
require.NoError(t, err) require.NoError(t, err)
// and make sure it has the proper info // and make sure it has the proper info


+ 2
- 2
rpc/client/helpers.go View File

@ -57,9 +57,9 @@ func WaitForHeight(ctx context.Context, c StatusClient, h int64, waiter Waiter)
// when the timeout duration has expired. // when the timeout duration has expired.
// //
// This handles subscribing and unsubscribing under the hood // This handles subscribing and unsubscribing under the hood
func WaitForOneEvent(c EventsClient, eventValue string, timeout time.Duration) (types.EventData, error) {
func WaitForOneEvent(ctx context.Context, c EventsClient, eventValue string, timeout time.Duration) (types.EventData, error) {
const subscriber = "helpers" const subscriber = "helpers"
ctx, cancel := context.WithTimeout(context.Background(), timeout)
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel() defer cancel()
// register for the next event of this type // register for the next event of this type


+ 1
- 1
rpc/client/http/ws.go View File

@ -140,7 +140,7 @@ func (w *wsEvents) UnsubscribeAll(ctx context.Context, subscriber string) error
func (w *wsEvents) redoSubscriptionsAfter(d time.Duration) { func (w *wsEvents) redoSubscriptionsAfter(d time.Duration) {
time.Sleep(d) time.Sleep(d)
ctx := context.Background()
ctx := context.TODO()
w.mtx.Lock() w.mtx.Lock()
defer w.mtx.Unlock() defer w.mtx.Unlock()


+ 2
- 2
rpc/client/main_test.go View File

@ -15,10 +15,10 @@ import (
rpctest "github.com/tendermint/tendermint/rpc/test" rpctest "github.com/tendermint/tendermint/rpc/test"
) )
func NodeSuite(t *testing.T, logger log.Logger) (service.Service, *config.Config) {
func NodeSuite(ctx context.Context, t *testing.T, logger log.Logger) (service.Service, *config.Config) {
t.Helper() t.Helper()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(ctx)
conf, err := rpctest.CreateConfig(t, t.Name()) conf, err := rpctest.CreateConfig(t, t.Name())
require.NoError(t, err) require.NoError(t, err)


+ 4
- 4
rpc/client/rpc_test.go View File

@ -95,7 +95,7 @@ func TestClientOperations(t *testing.T) {
logger := log.NewTestingLogger(t) logger := log.NewTestingLogger(t)
_, conf := NodeSuite(t, logger)
_, conf := NodeSuite(ctx, t, logger)
t.Run("NilCustomHTTPClient", func(t *testing.T) { t.Run("NilCustomHTTPClient", func(t *testing.T) {
_, err := rpchttp.NewWithClient("http://example.com", nil) _, err := rpchttp.NewWithClient("http://example.com", nil)
@ -193,7 +193,7 @@ func TestClientMethodCalls(t *testing.T) {
defer cancel() defer cancel()
logger := log.NewTestingLogger(t) logger := log.NewTestingLogger(t)
n, conf := NodeSuite(t, logger)
n, conf := NodeSuite(ctx, t, logger)
// for broadcast tx tests // for broadcast tx tests
pool := getMempool(t, n) pool := getMempool(t, n)
@ -471,7 +471,7 @@ func TestClientMethodCalls(t *testing.T) {
}) })
t.Run("Events", func(t *testing.T) { t.Run("Events", func(t *testing.T) {
t.Run("Header", func(t *testing.T) { t.Run("Header", func(t *testing.T) {
evt, err := client.WaitForOneEvent(c, types.EventNewBlockHeaderValue, waitForEventTimeout)
evt, err := client.WaitForOneEvent(ctx, c, types.EventNewBlockHeaderValue, waitForEventTimeout)
require.NoError(t, err, "%d: %+v", i, err) require.NoError(t, err, "%d: %+v", i, err)
_, ok := evt.(types.EventDataNewBlockHeader) _, ok := evt.(types.EventDataNewBlockHeader)
require.True(t, ok, "%d: %#v", i, evt) require.True(t, ok, "%d: %#v", i, evt)
@ -583,7 +583,7 @@ func TestClientMethodCallsAdvanced(t *testing.T) {
logger := log.NewTestingLogger(t) logger := log.NewTestingLogger(t)
n, conf := NodeSuite(t, logger)
n, conf := NodeSuite(ctx, t, logger)
pool := getMempool(t, n) pool := getMempool(t, n)
t.Run("UnconfirmedTxs", func(t *testing.T) { t.Run("UnconfirmedTxs", func(t *testing.T) {


+ 1
- 1
test/e2e/node/main.go View File

@ -175,7 +175,7 @@ func startLightNode(ctx context.Context, cfg *Config) error {
providers := rpcEndpoints(tmcfg.P2P.PersistentPeers) providers := rpcEndpoints(tmcfg.P2P.PersistentPeers)
c, err := light.NewHTTPClient( c, err := light.NewHTTPClient(
context.Background(),
ctx,
cfg.ChainID, cfg.ChainID,
light.TrustOptions{ light.TrustOptions{
Period: tmcfg.StateSync.TrustPeriod, Period: tmcfg.StateSync.TrustPeriod,


+ 2
- 3
test/e2e/runner/benchmark.go View File

@ -43,7 +43,7 @@ func Benchmark(ctx context.Context, testnet *e2e.Testnet, benchmarkLength int64)
logger.Info("Ending benchmark period", "height", block.Height) logger.Info("Ending benchmark period", "height", block.Height)
// fetch a sample of blocks // fetch a sample of blocks
blocks, err := fetchBlockChainSample(testnet, benchmarkLength)
blocks, err := fetchBlockChainSample(ctx, testnet, benchmarkLength)
if err != nil { if err != nil {
return err return err
} }
@ -128,7 +128,7 @@ func (t *testnetStats) String() string {
// fetchBlockChainSample waits for `benchmarkLength` amount of blocks to pass, fetching // fetchBlockChainSample waits for `benchmarkLength` amount of blocks to pass, fetching
// all of the headers for these blocks from an archive node and returning it. // all of the headers for these blocks from an archive node and returning it.
func fetchBlockChainSample(testnet *e2e.Testnet, benchmarkLength int64) ([]*types.BlockMeta, error) {
func fetchBlockChainSample(ctx context.Context, testnet *e2e.Testnet, benchmarkLength int64) ([]*types.BlockMeta, error) {
var blocks []*types.BlockMeta var blocks []*types.BlockMeta
// Find the first archive node // Find the first archive node
@ -139,7 +139,6 @@ func fetchBlockChainSample(testnet *e2e.Testnet, benchmarkLength int64) ([]*type
} }
// find the latest height // find the latest height
ctx := context.Background()
s, err := c.Status(ctx) s, err := c.Status(ctx)
if err != nil { if err != nil {
return nil, err return nil, err


Loading…
Cancel
Save