Skip to content

Commit

Permalink
use cleanup function
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilGeorgiev committed Jun 23, 2024
1 parent a88a94c commit 5d7a70f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
9 changes: 7 additions & 2 deletions tests/rpc/rpc_01-system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package rpc

import (
"context"
"fmt"
"testing"
"time"

Expand All @@ -21,7 +22,11 @@ import (
const peerIDRegex = `^[a-zA-Z0-9]{52}$`

func TestSystemRPC(t *testing.T) { //nolint:tparallel
t.Logf("TestSystemRPC START AT: %s", time.Now().String())
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestSystemRPC total test time: %v", elapsedTime)
})
const testTimeout = 8 * time.Minute
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)

Expand All @@ -37,6 +42,7 @@ func TestSystemRPC(t *testing.T) { //nolint:tparallel
nodes.InitAndStartTest(ctx, t, cancel)

t.Run("system_health", func(t *testing.T) {
fmt.Println("MIDDLEEEEEEEEEEEEE")
t.Parallel()

const method = "system_health"
Expand Down Expand Up @@ -197,5 +203,4 @@ func TestSystemRPC(t *testing.T) { //nolint:tparallel
t.Parallel()
t.Skip("test not implemented")
})
t.Logf("TestSystemRPC END AT: %s", time.Now().String())
}
14 changes: 10 additions & 4 deletions tests/rpc/rpc_02-author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import (
// TODO: add test against latest dev runtime
// See https://github.com/ChainSafe/gossamer/issues/2705
func TestAuthorSubmitExtrinsic(t *testing.T) {
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestAuthorSubmitExtrinsic total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Account.Key = config.AliceKey
Expand Down Expand Up @@ -94,11 +98,14 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
hash, err := api.RPC.Author.SubmitExtrinsic(ext)
require.NoError(t, err)
require.NotEqual(t, types.Hash{}, hash)
t.Logf("TestAuthorSubmitExtrinsic FINISHED FOR: %v", time.Since(nn))
}

func TestAuthorRPC(t *testing.T) { //nolint:tparallel
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestAuthorRPC total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand Down Expand Up @@ -169,5 +176,4 @@ func TestAuthorRPC(t *testing.T) { //nolint:tparallel
var target interface{} // TODO
fetchWithTimeout(ctx, t, "author_hasKey", "", target)
})
t.Logf("TestAuthorRPC FINISHED FOR: %v", time.Since(nn))
}
14 changes: 10 additions & 4 deletions tests/rpc/rpc_03-chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const (
)

func TestChainRPC(t *testing.T) {
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestChainRPC total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand Down Expand Up @@ -132,11 +136,14 @@ func TestChainRPC(t *testing.T) {
fetchWithTimeout(ctx, t, "chain_getBlockHash", "[]", &blockHash)
assert.Regexp(t, regex32BytesHex, blockHash)
assert.NotEqual(t, finalizedHash, blockHash)
t.Logf("TestChainRPC FINISHED FOR: %v", time.Since(nn))
}

func TestChainSubscriptionRPC(t *testing.T) { //nolint:tparallel
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestChainSubscriptionRPC total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand Down Expand Up @@ -266,7 +273,6 @@ func TestChainSubscriptionRPC(t *testing.T) { //nolint:tparallel
assert.GreaterOrEqual(t, blockNumber, blockNumbers[i-1])
}
})
t.Logf("TestChainSubscriptionRPC FINISHED FOR: %v", time.Since(nn))
}

func getResultMapFromParams(t *testing.T, params subscription.Params) (
Expand Down
21 changes: 15 additions & 6 deletions tests/rpc/rpc_05-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import (
)

func TestStateRPCResponseValidation(t *testing.T) { //nolint:tparallel
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestStateRPCResponseValidation total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand Down Expand Up @@ -198,11 +202,14 @@ func TestStateRPCResponseValidation(t *testing.T) { //nolint:tparallel

// TODO assert response
})
t.Logf("TestStateRPCResponseValidation FINISHED FOR: %v", time.Since(nn))
}

func TestStateRPCAPI(t *testing.T) {
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestStateRPCAPI total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendLocalRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand Down Expand Up @@ -402,11 +409,14 @@ func TestStateRPCAPI(t *testing.T) {
require.Contains(t, string(respBody), test.expected)
})
}
t.Logf("TestStateRPCAPI FINISHED FOR: %v", time.Since(nn))
}

func TestRPCStructParamUnmarshal(t *testing.T) {
nn := time.Now()
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestRPCStructParamUnmarshal total test time: %v", elapsedTime)
})
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.ChainSpec = genesisPath
Expand All @@ -430,5 +440,4 @@ func TestRPCStructParamUnmarshal(t *testing.T) {
require.NotContains(t, string(respBody), "json: cannot unmarshal")
fmt.Println(string(respBody))
})
t.Logf("TestRPCStructParamUnmarshal FINISHED FOR: %v", time.Since(nn))
}
8 changes: 5 additions & 3 deletions tests/rpc/system_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import (
)

func TestStableNetworkRPC(t *testing.T) { //nolint:tparallel
nn := time.Now()
t.Logf("Start test at: %s", time.Now().String())
startTime := time.Now()
t.Cleanup(func() {
elapsedTime := time.Since(startTime)
t.Logf("TestStableNetworkRPC total test time: %v", elapsedTime)
})
//if utils.MODE != "rpc" {
//t.Skip("RPC tests are disabled, going to skip.")
//}
Expand Down Expand Up @@ -171,7 +174,6 @@ func TestStableNetworkRPC(t *testing.T) { //nolint:tparallel
})
})
}
t.Logf("TestStableNetworkRPC FINISHED FOR: %v", time.Since(nn))
}

func fetchWithTimeoutFromEndpoint(t *testing.T, endpoint, method string, target interface{}) {
Expand Down

0 comments on commit 5d7a70f

Please sign in to comment.