Skip to content

Commit

Permalink
Add parallelizm to some Docker functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Dec 3, 2024
1 parent 2af500b commit 4f8b6b7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 39 deletions.
19 changes: 9 additions & 10 deletions itests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
102 changes: 73 additions & 29 deletions itests/utilities/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 4f8b6b7

Please sign in to comment.