From f876952aa8dd2eab50212b6468570339647784cd Mon Sep 17 00:00:00 2001 From: Pantani Date: Sat, 20 Apr 2024 02:51:14 +0200 Subject: [PATCH 1/4] fix race condition for unit tests --- ignite/internal/plugin/execute.go | 3 ++- ignite/pkg/cosmosanalysis/app/app.go | 1 - ignite/pkg/cosmosanalysis/cosmosanalysis.go | 2 -- ignite/pkg/cosmosgen/generate_vuex.go | 2 -- ignite/pkg/goanalysis/goanalysis.go | 1 - ignite/pkg/repoversion/repoversion.go | 2 -- ignite/services/plugin/protocol.go | 6 ++++++ scripts/test-coverage | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ignite/internal/plugin/execute.go b/ignite/internal/plugin/execute.go index 746a071631..70dc1ac395 100644 --- a/ignite/internal/plugin/execute.go +++ b/ignite/internal/plugin/execute.go @@ -35,11 +35,12 @@ func Execute(ctx context.Context, path string, args []string, options ...plugin. if err != nil { // Extract the rpc status message and create a simple error from it. // We don't want Execute to return rpc errors. - err = errors.New(status.Convert(err).Message()) + return "", errors.New(status.Convert(err).Message()) } // NOTE(tb): This pause gives enough time for go-plugin to sync the // output from stdout/stderr of the plugin. Without that pause, this // output can be discarded and absent from buf. time.Sleep(100 * time.Millisecond) + plugins[0].KillClient() return buf.String(), err } diff --git a/ignite/pkg/cosmosanalysis/app/app.go b/ignite/pkg/cosmosanalysis/app/app.go index eeda44dac9..cac4ba3036 100644 --- a/ignite/pkg/cosmosanalysis/app/app.go +++ b/ignite/pkg/cosmosanalysis/app/app.go @@ -237,7 +237,6 @@ func discoverRuntimeAppModules(chainRoot string) ([]string, error) { } return nil }) - if err != nil { return nil, err } diff --git a/ignite/pkg/cosmosanalysis/cosmosanalysis.go b/ignite/pkg/cosmosanalysis/cosmosanalysis.go index c316205dec..46e4f2f806 100644 --- a/ignite/pkg/cosmosanalysis/cosmosanalysis.go +++ b/ignite/pkg/cosmosanalysis/cosmosanalysis.go @@ -53,7 +53,6 @@ func DeepFindImplementation(modulePath string, interfaceList []string) (found [] found = append(found, currFound...) return nil }) - if err != nil { return nil, err } @@ -267,7 +266,6 @@ func FindAppFilePath(chainRoot string) (path string, err error) { return nil }) - if err != nil { return "", err } diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index 5add23c832..160a4c653d 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -69,7 +69,6 @@ func (g *generator) updateVueDependencies() error { tsClientName: fmt.Sprintf("file:%s", tsClientVueRelPath), }, }) - if err != nil { return errors.Errorf("failed to link ts-client dependency to the Vue app: %w", err) } @@ -136,7 +135,6 @@ func (g *generator) updateVuexDependencies() error { tsClientName: fmt.Sprintf("file:%s", tsClientVuexRelPath), }, }) - if err != nil { return errors.Errorf("failed to link ts-client dependency to the Vuex stores: %w", err) } diff --git a/ignite/pkg/goanalysis/goanalysis.go b/ignite/pkg/goanalysis/goanalysis.go index d219f1d5ed..d0e6c30c55 100644 --- a/ignite/pkg/goanalysis/goanalysis.go +++ b/ignite/pkg/goanalysis/goanalysis.go @@ -45,7 +45,6 @@ func DiscoverMain(path string) (pkgPaths []string, err error) { return nil }) - if err != nil { return nil, err } diff --git a/ignite/pkg/repoversion/repoversion.go b/ignite/pkg/repoversion/repoversion.go index 4428a5d41b..f2f3e560ec 100644 --- a/ignite/pkg/repoversion/repoversion.go +++ b/ignite/pkg/repoversion/repoversion.go @@ -50,7 +50,6 @@ func Determine(path string) (v Version, err error) { return nil }) - if err != nil { return Version{}, err } @@ -94,7 +93,6 @@ func Determine(path string) (v Version, err error) { return nil }) - if err != nil { return Version{}, err } diff --git a/ignite/services/plugin/protocol.go b/ignite/services/plugin/protocol.go index 5e5a92b111..657609165b 100644 --- a/ignite/services/plugin/protocol.go +++ b/ignite/services/plugin/protocol.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "sync" hplugin "github.com/hashicorp/go-plugin" "google.golang.org/grpc" @@ -108,19 +109,24 @@ func (c client) ExecuteHookCleanUp(ctx context.Context, h *ExecutedHook, api Cli func (c client) startClientAPIServer(api ClientAPI) (uint32, func()) { var ( srv *grpc.Server + m sync.Mutex brokerID = c.broker.NextId() ) go c.broker.AcceptAndServe(brokerID, func(opts []grpc.ServerOption) *grpc.Server { + m.Lock() + defer m.Unlock() srv = grpc.NewServer(opts...) v1.RegisterClientAPIServiceServer(srv, &clientAPIServer{impl: api}) return srv }) stop := func() { + m.Lock() if srv != nil { srv.Stop() } + m.Unlock() } return brokerID, stop diff --git a/scripts/test-coverage b/scripts/test-coverage index 317a19f057..58d3591e8c 100755 --- a/scripts/test-coverage +++ b/scripts/test-coverage @@ -1,7 +1,7 @@ #!/bin/bash set -e -x -go test -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list github.com/ignite/cli/v29/ignite/...) +go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list github.com/ignite/cli/v29/ignite/...) # append "||true" to grep so if no match the return code stays 0 excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER' || true)" From 6824c3d0b74d530029d8aa745693c7ad682dbe0d Mon Sep 17 00:00:00 2001 From: Pantani Date: Sat, 20 Apr 2024 02:52:33 +0200 Subject: [PATCH 2/4] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 4bdfddd697..08fa61554f 100644 --- a/changelog.md +++ b/changelog.md @@ -29,6 +29,7 @@ - [#3969](https://github.com/ignite/cli/pull/3969) Get first config validator using a getter to avoid index errors - [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg - [#4086](https://github.com/ignite/cli/pull/4086) Retry to get the IBC balance if it fails the first time +- [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic ## [`v28.3.0`](https://github.com/ignite/cli/releases/tag/v28.3.0) From 2eb3e023459a9e26e3b7b5cc477af0b5a0b338ad Mon Sep 17 00:00:00 2001 From: Pantani Date: Mon, 22 Apr 2024 12:05:57 +0200 Subject: [PATCH 3/4] increase TestScaffoldedTests timeout --- ignite/services/plugin/scaffold_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/services/plugin/scaffold_test.go b/ignite/services/plugin/scaffold_test.go index 3268fa51c6..6937ac1e2d 100644 --- a/ignite/services/plugin/scaffold_test.go +++ b/ignite/services/plugin/scaffold_test.go @@ -52,7 +52,7 @@ func TestScaffoldedTests(t *testing.T) { // Act err := gocmd.Test(ctx, path, []string{ "-timeout", - "5m", + "10m", "-run", "^TestBar$", }) From c2b64efd04d08adb91d381aebe16c827db11cd21 Mon Sep 17 00:00:00 2001 From: Pantani Date: Mon, 22 Apr 2024 12:48:11 +0200 Subject: [PATCH 4/4] decrease integration tests timeout --- scripts/test-integration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test-integration b/scripts/test-integration index 4951f1e8ac..e763b012dd 100755 --- a/scripts/test-integration +++ b/scripts/test-integration @@ -1,3 +1,3 @@ #!/bin/bash -go test -v -timeout 120m github.com/ignite/cli/v29/integration/... +go test -v -timeout 30m github.com/ignite/cli/v29/integration/...