mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
added TermintionWaitGroup (#336)
* added TermintionWaitGroup * added mutex to lib/tx * removed machine attestation thread (to comply with testing-race conditions becoming apparent on the CI) * renamed test suites to have a clear naming structure * removed parallel-testing from e2e machine test suite * improved test suite logging * removed parallel tests of machine_nft_tests - this caused data races due to the mock overwrites * reduced error check to "out of gas" due to multi-threading and locking delays that result in different gas consumptions * Added waiting blocks to pass the CI Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
f13c54f582
commit
31b304f232
@ -109,6 +109,9 @@ issues:
|
||||
- path: tests/.*/*\.go
|
||||
linters:
|
||||
- paralleltest
|
||||
- path: util/machine_nft_test\.go
|
||||
linters:
|
||||
- paralleltest
|
||||
- path: testutil/network/network.go
|
||||
linters:
|
||||
- gocognit
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
func TestE2ELibTestSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := network.DefaultConfig()
|
||||
cfg.NumValidators = 1
|
||||
|
@ -29,14 +29,14 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
|
||||
// SetupSuite initializes machine E2ETestSuite
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e lib test suite")
|
||||
|
||||
s.network = network.New(s.T())
|
||||
}
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
s.T().Log("tearing down e2e lib test suite")
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestBankSendBroadcastTxWithFileLock() {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
comethttp "github.com/cometbft/cometbft/rpc/client/http"
|
||||
@ -17,7 +18,10 @@ import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
var ErrTypeAssertionFailed = errors.New("type assertion failed")
|
||||
var (
|
||||
ErrTypeAssertionFailed = errors.New("type assertion failed")
|
||||
LibSyncAccess sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
GetConfig()
|
||||
@ -172,6 +176,8 @@ func broadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (out
|
||||
|
||||
// BroadcastTxWithFileLock broadcasts a transaction via gRPC and synchronises requests via a file lock.
|
||||
func BroadcastTxWithFileLock(fromAddress sdk.AccAddress, msgs ...sdk.Msg) (out *bytes.Buffer, err error) {
|
||||
LibSyncAccess.Lock()
|
||||
defer LibSyncAccess.Unlock()
|
||||
// open and lock file, if it exists
|
||||
file, err := openSequenceFile(fromAddress)
|
||||
if err != nil {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
func TestE2EAssetTestSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
|
||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
@ -29,7 +30,7 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
|
||||
// SetupSuite initializes asset E2ETestSuite
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e asset test suite")
|
||||
|
||||
s.network = network.Load(s.T(), s.cfg)
|
||||
err := e2etestutil.AttestMachine(s.network, sample.Name, sample.Mnemonic, 0, sample.FeeDenom)
|
||||
@ -38,7 +39,8 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e asset test suite")
|
||||
}
|
||||
|
||||
// TestNotarizeAsset notarizes asset over cli
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -25,7 +26,7 @@ func NewAssetDistributionE2ETestSuite(cfg network.Config) *AssetDistributionE2ET
|
||||
}
|
||||
|
||||
func (s *AssetDistributionE2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e dao distribution test suite")
|
||||
|
||||
// set epochs: make sure to start after initial height of 7
|
||||
s.distributionOffset = 5
|
||||
@ -41,7 +42,8 @@ func (s *AssetDistributionE2ETestSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (s *AssetDistributionE2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suites")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e dao distribution test suites")
|
||||
}
|
||||
|
||||
func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
|
||||
|
@ -8,31 +8,31 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
func TestE2EDaoTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
||||
|
||||
func TestPopE2ETestSuite(t *testing.T) {
|
||||
func TestPopE2EDaoTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewPopSelectionE2ETestSuite(cfg))
|
||||
}
|
||||
|
||||
func TestGasConsumptionE2ETestSuite(t *testing.T) {
|
||||
func TestGasConsumptionE2EDaoTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewGasConsumptionE2ETestSuite(cfg))
|
||||
}
|
||||
|
||||
func TestRestrictedMsgsE2ETestSuite(t *testing.T) {
|
||||
func TestRestrictedMsgsE2EDaoTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewRestrictedMsgsE2ESuite(cfg))
|
||||
}
|
||||
|
||||
func TestAssetDistributionE2ETestSuite(t *testing.T) {
|
||||
func TestAssetDistributionE2EDaoTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewAssetDistributionE2ETestSuite(cfg))
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -63,7 +64,7 @@ func (s *GasConsumptionE2ETestSuite) createValAccount(cfg network.Config) (addre
|
||||
}
|
||||
|
||||
func (s *GasConsumptionE2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e dao gas consumption test suite")
|
||||
|
||||
s.feeDenom = sample.FeeDenom
|
||||
s.cfg.Mnemonics = []string{sample.Mnemonic}
|
||||
@ -93,7 +94,8 @@ func (s *GasConsumptionE2ETestSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (s *GasConsumptionE2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suites")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e dao gas consumption test suites")
|
||||
}
|
||||
|
||||
func (s *GasConsumptionE2ETestSuite) TestValidatorConsumption() {
|
||||
@ -136,7 +138,7 @@ func (s *GasConsumptionE2ETestSuite) TestNonValidatorConsumptionOverflow() {
|
||||
|
||||
_, err = clitestutil.GetRawLogFromTxOut(val, out)
|
||||
s.Require().Error(err)
|
||||
assert.Equal(s.T(), "out of gas in location: ReadFlat; gasWanted: 200000, gasUsed: 200316: out of gas", err.Error())
|
||||
assert.Contains(s.T(), err.Error(), "out of gas")
|
||||
}
|
||||
|
||||
func (s *GasConsumptionE2ETestSuite) createMsgs(from sdk.AccAddress, to sdk.AccAddress, n int) (msgs []sdk.Msg) {
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -61,7 +62,7 @@ func NewPopSelectionE2ETestSuite(cfg network.Config) *PopSelectionE2ETestSuite {
|
||||
}
|
||||
|
||||
func (s *PopSelectionE2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e dao pop selection test suite")
|
||||
|
||||
s.popEpochs = 10
|
||||
s.reissuanceEpochs = 60
|
||||
@ -86,7 +87,8 @@ func (s *PopSelectionE2ETestSuite) SetupSuite() {
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *PopSelectionE2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e dao pop selection test suite")
|
||||
}
|
||||
|
||||
func (s *PopSelectionE2ETestSuite) perpareLocalTest() testutil.BufferWriter {
|
||||
@ -244,6 +246,8 @@ func (s *PopSelectionE2ETestSuite) TestTokenDistribution1() {
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
s.VerifyTokens(daoGenState.Params.ClaimDenom)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -34,7 +35,7 @@ func NewRestrictedMsgsE2ESuite(cfg network.Config) *RestrictedMsgsE2ESuite {
|
||||
}
|
||||
|
||||
func (s *RestrictedMsgsE2ESuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e dao restricted msg test suite")
|
||||
|
||||
s.network = network.Load(s.T(), s.cfg)
|
||||
account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||
@ -44,7 +45,8 @@ func (s *RestrictedMsgsE2ESuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (s *RestrictedMsgsE2ESuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e dao restricted msg test suite")
|
||||
}
|
||||
|
||||
func (s *RestrictedMsgsE2ESuite) TestRestrictedMsgsValidator() {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -48,7 +49,7 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
s.reissuanceEpochs = 25
|
||||
s.distributionOffset = 5
|
||||
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e dao test suite")
|
||||
|
||||
// Setup MintAddress parameter in genesis state
|
||||
// use sample.Mnemonic to make mint address deterministic for test
|
||||
@ -109,7 +110,8 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e dao test suite")
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestMintToken() {
|
||||
|
@ -8,8 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
func TestE2EMachineTestSuite(t *testing.T) {
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg.NumValidators = 3
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
"github.com/planetmint/planetmint-go/util"
|
||||
machinecli "github.com/planetmint/planetmint-go/x/machine/client/cli"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
|
||||
@ -35,7 +36,7 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
|
||||
// SetupSuite initializes machine E2ETestSuite
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
s.T().Log("setting up e2e machine test suite")
|
||||
|
||||
s.feeDenom = sample.FeeDenom
|
||||
s.network = network.Load(s.T(), s.cfg)
|
||||
@ -49,7 +50,8 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
util.TerminationWaitGroup.Wait()
|
||||
s.T().Log("tearing down e2e machine test suite")
|
||||
}
|
||||
|
||||
// TestAttestMachine attests machine and query attested machine from chain
|
||||
|
@ -14,7 +14,9 @@ import (
|
||||
func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
GetAppLogger().Info(ctx, loggingContext+": "+msg.String())
|
||||
TerminationWaitGroup.Add(1)
|
||||
go func() {
|
||||
defer TerminationWaitGroup.Done()
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
|
||||
txJSON, err := lib.BuildUnsignedTx(addr, msg)
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
)
|
||||
|
||||
func TestRegisterNFT(t *testing.T) {
|
||||
t.Parallel()
|
||||
url := "https://testnet-assets.rddl.io/register_asset"
|
||||
contract := `{"entity":{"domain":"testnet-assets.rddl.io"},"issuer_pubkey":"020000000000000000000000000000000000000000000000000000000000000000","machine_addr":"plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877","name":"machine","precision":0,"version":0}`
|
||||
asset := "0000000000000000000000000000000000000000000000000000000000000000"
|
||||
@ -28,8 +27,6 @@ func TestRegisterNFT(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMachineNFTIssuance(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
elements.Client = &elementsmocks.MockClient{}
|
||||
util.RegisterAssetServiceHTTPClient = &mocks.MockClient{}
|
||||
_, ctx := keeper.MachineKeeper(t)
|
||||
|
5
util/sync.go
Normal file
5
util/sync.go
Normal file
@ -0,0 +1,5 @@
|
||||
package util
|
||||
|
||||
import "sync"
|
||||
|
||||
var TerminationWaitGroup sync.WaitGroup
|
Loading…
x
Reference in New Issue
Block a user