From 4f8b6b707527047f83ac55c64355b76c41ab2994 Mon Sep 17 00:00:00 2001 From: Alexey Kiselev Date: Tue, 3 Dec 2024 14:21:47 +0400 Subject: [PATCH] Add parallelizm to some Docker functions. --- itests/docker/docker.go | 19 ++++--- itests/utilities/common.go | 102 ++++++++++++++++++++++++++----------- 2 files changed, 82 insertions(+), 39 deletions(-) diff --git a/itests/docker/docker.go b/itests/docker/docker.go index 18becca08..f7d9ac097 100644 --- a/itests/docker/docker.go +++ b/itests/docker/docker.go @@ -21,7 +21,9 @@ import ( ) const ( - DefaultTimeout = 16 * time.Second + DefaultTimeout = 16 * time.Second + PoolRetryTimeout = 2 * time.Minute + DefaultAPIKey = "itest-api-key" networkName = "waves-it-network" goNodeLogFileName = "go-node.log" @@ -109,6 +111,7 @@ func NewDocker(suiteName string) (*Docker, error) { if err != nil { return nil, err } + pool.MaxWait = PoolRetryTimeout docker := &Docker{suite: suiteName, pool: pool} if rmErr := docker.removeContainers(); rmErr != nil { return nil, rmErr @@ -142,16 +145,10 @@ func (d *Docker) ScalaNode() *NodeContainer { func (d *Docker) StartNodes(ctx context.Context, goCfg, scalaCfg config.DockerConfigurator) error { eg := errgroup.Group{} eg.Go(func() error { - if err := d.StartGoNode(ctx, goCfg); err != nil { - return err - } - return nil + return d.StartGoNode(ctx, goCfg) }) eg.Go(func() error { - if err := d.StartScalaNode(ctx, scalaCfg); err != nil { - return err - } - return nil + return d.StartScalaNode(ctx, scalaCfg) }) return eg.Wait() } @@ -223,7 +220,7 @@ func (d *Docker) stopContainer(containerID string) error { if stErr := d.pool.Client.StopContainer(containerID, shutdownTimeout); stErr != nil { if klErr := d.pool.Client.KillContainer(dc.KillContainerOptions{ ID: containerID, - Signal: dc.SIGINT, + Signal: dc.SIGKILL, }); klErr != nil { return errors.Wrapf(stderrs.Join(stErr, klErr), "failed to stop container %q", containerID) } @@ -291,9 +288,11 @@ func (d *Docker) startNode( ApiKey: DefaultAPIKey, }) if fErr != nil { + log.Printf("Failed to create client for container %q: %v", res.Container.Name, fErr) return fErr } _, _, fErr = nodeClient.Blocks.Height(ctx) + log.Printf("Result requesting height from container %q: %v", res.Container.Name, fErr) return fErr }) if err != nil { diff --git a/itests/utilities/common.go b/itests/utilities/common.go index 960823072..0d6f52924 100644 --- a/itests/utilities/common.go +++ b/itests/utilities/common.go @@ -394,8 +394,16 @@ func GetHeightScala(suite *f.BaseSuite) uint64 { } func GetHeight(suite *f.BaseSuite) uint64 { - goHeight := GetHeightGo(suite) - scalaHeight := GetHeightScala(suite) + goCh := make(chan uint64) + scalaCh := make(chan uint64) + go func() { + goCh <- GetHeightGo(suite) + }() + go func() { + scalaCh <- GetHeightScala(suite) + }() + goHeight := <-goCh + scalaHeight := <-scalaCh if goHeight < scalaHeight { return goHeight } @@ -481,30 +489,41 @@ func GetFeatureActivationHeightScala(suite *f.BaseSuite, featureID settings.Feat } func GetFeatureActivationHeight(suite *f.BaseSuite, featureID settings.Feature, height uint64) proto.Height { - var err error - var activationHeight proto.Height - activationHeightGo := GetFeatureActivationHeightGo(suite, featureID, height) - activationHeightScala := GetFeatureActivationHeightScala(suite, featureID, height) + goCh := make(chan proto.Height) + scalaCh := make(chan proto.Height) + go func() { + goCh <- GetFeatureActivationHeightGo(suite, featureID, height) + }() + go func() { + scalaCh <- GetFeatureActivationHeightScala(suite, featureID, height) + }() + activationHeightGo := <-goCh + activationHeightScala := <-scalaCh + if activationHeightGo == activationHeightScala && activationHeightGo > 0 { - activationHeight = activationHeightGo - } else { - err = errors.New("Activation Height from Go and Scala is different") + return activationHeightGo } - require.NoError(suite.T(), err) - return activationHeight + + suite.FailNow("Activation Height from Go and Scala is different") + return 0 } func GetFeatureBlockchainStatus(suite *f.BaseSuite, featureID settings.Feature, height uint64) (string, error) { - var status string - var err error - statusGo := GetFeatureBlockchainStatusGo(suite, featureID, height) - statusScala := GetFeatureBlockchainStatusScala(suite, featureID, height) + goCh := make(chan string) + scalaCh := make(chan string) + go func() { + goCh <- GetFeatureBlockchainStatusGo(suite, featureID, height) + }() + go func() { + scalaCh <- GetFeatureBlockchainStatusScala(suite, featureID, height) + }() + statusGo := <-goCh + statusScala := <-scalaCh + if statusGo == statusScala { - status = statusGo - } else { - err = errors.Errorf("Feature with Id %d has different statuses", featureID) + return statusGo, nil } - return status, err + return "", errors.Errorf("Feature with ID %d has different statuses", featureID) } func GetWaitingBlocks(suite *f.BaseSuite, height uint64, featureID settings.Feature) uint64 { @@ -531,17 +550,26 @@ func GetWaitingBlocks(suite *f.BaseSuite, height uint64, featureID settings.Feat } func WaitForFeatureActivation(suite *f.BaseSuite, featureID settings.Feature, height uint64) proto.Height { - var activationHeight proto.Height waitingBlocks := GetWaitingBlocks(suite, height, featureID) h := WaitForHeight(suite, height+waitingBlocks) - activationHeightGo := GetFeatureActivationHeightGo(suite, featureID, h) - activationHeightScala := GetFeatureActivationHeightScala(suite, featureID, h) + + goCh := make(chan proto.Height) + scalaCh := make(chan proto.Height) + + go func() { + goCh <- GetFeatureActivationHeightGo(suite, featureID, h) + }() + go func() { + scalaCh <- GetFeatureActivationHeightScala(suite, featureID, h) + }() + activationHeightGo := <-goCh + activationHeightScala := <-scalaCh + if activationHeightScala == activationHeightGo { - activationHeight = activationHeightGo - } else { - suite.FailNowf("Feature has different activation heights", "Feature ID is %d", featureID) + return activationHeightGo } - return activationHeight + suite.FailNowf("Feature has different activation heights", "Feature ID is %d", featureID) + return 0 } func FeatureShouldBeActivated(suite *f.BaseSuite, featureID settings.Feature, height uint64) { @@ -884,8 +912,16 @@ func GetRewardTermAtHeightScala(suite *f.BaseSuite, height uint64) uint64 { } func GetRewardTermAtHeight(suite *f.BaseSuite, height uint64) RewardTerm { - termGo := GetRewardTermAtHeightGo(suite, height) - termScala := GetRewardTermAtHeightScala(suite, height) + goCh := make(chan uint64) + scalaCh := make(chan uint64) + go func() { + goCh <- GetRewardTermAtHeightGo(suite, height) + }() + go func() { + scalaCh <- GetRewardTermAtHeightScala(suite, height) + }() + termGo := <-goCh + termScala := <-scalaCh suite.T().Logf("Go: Reward Term: %d, Scala: Reward Term: %d, height: %d", termGo, termScala, height) return NewRewardTerm(termGo, termScala) @@ -917,5 +953,13 @@ func GetRollbackToHeightScala(suite *f.BaseSuite, height uint64, returnTxToUtx b func GetRollbackToHeight(suite *f.BaseSuite, height uint64, returnTxToUtx bool) (*proto.BlockID, *proto.BlockID) { suite.T().Logf("Rollback to height: %d from height: %d", height, GetHeight(suite)) - return GetRollbackToHeightGo(suite, height, returnTxToUtx), GetRollbackToHeightScala(suite, height, returnTxToUtx) + goCh := make(chan *proto.BlockID) + scalaCh := make(chan *proto.BlockID) + go func() { + goCh <- GetRollbackToHeightGo(suite, height, returnTxToUtx) + }() + go func() { + scalaCh <- GetRollbackToHeightScala(suite, height, returnTxToUtx) + }() + return <-goCh, <-scalaCh }