From 72fb47fbd833e5d584e874237987d6c235949275 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Tue, 8 Oct 2024 16:09:43 +0800 Subject: [PATCH] fix e2e --- finality-provider/service/fp_manager.go | 11 +++++------ itest/e2e_test.go | 10 ++-------- itest/test_manager.go | 4 +--- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/finality-provider/service/fp_manager.go b/finality-provider/service/fp_manager.go index 2acc2b67..c52d5b85 100644 --- a/finality-provider/service/fp_manager.go +++ b/finality-provider/service/fp_manager.go @@ -37,7 +37,6 @@ type FinalityProviderManager struct { isStarted *atomic.Bool // mutex to acess map of fp instances (fpIns) - mu sync.Mutex wg sync.WaitGroup fpIns *FinalityProviderInstance @@ -265,12 +264,15 @@ func (fpm *FinalityProviderManager) Stop() error { return fmt.Errorf("the finality-provider manager has already stopped") } - close(fpm.quit) - fpm.wg.Wait() + defer func() { + close(fpm.quit) + fpm.wg.Wait() + }() if fpm.fpIns == nil { return nil } + if !fpm.fpIns.IsRunning() { return nil } @@ -354,9 +356,6 @@ func (fpm *FinalityProviderManager) startFinalityProviderInstance( pk *bbntypes.BIP340PubKey, passphrase string, ) error { - fpm.mu.Lock() - defer fpm.mu.Unlock() - pkHex := pk.MarshalHex() if fpm.fpIns == nil { fpIns, err := NewFinalityProviderInstance( diff --git a/itest/e2e_test.go b/itest/e2e_test.go index 6d87e81f..5fccea3d 100644 --- a/itest/e2e_test.go +++ b/itest/e2e_test.go @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/stretchr/testify/require" - "github.com/babylonlabs-io/finality-provider/finality-provider/proto" "github.com/babylonlabs-io/finality-provider/types" ) @@ -100,14 +99,9 @@ func TestDoubleSigning(t *testing.T) { tm.WaitForFpShutDown(t) - // try to start all the finality providers and the slashed one should not be restarted + // try to start the finality providers and the slashed one should expect err err = tm.Fpa.StartHandlingFinalityProvider(fpIns.GetBtcPkBIP340(), "") - require.NoError(t, err) - fps, err := tm.Fpa.ListAllFinalityProvidersInfo() - require.NoError(t, err) - require.Equal(t, 1, len(fps)) - require.Equal(t, proto.FinalityProviderStatus_name[4], fps[0].Status) - require.Equal(t, false, fps[0].IsRunning) + require.Error(t, err) } // TestFastSync tests the fast sync process where the finality-provider is terminated and restarted with fast sync diff --git a/itest/test_manager.go b/itest/test_manager.go index 96d75984..70c4abf1 100644 --- a/itest/test_manager.go +++ b/itest/test_manager.go @@ -252,9 +252,7 @@ func StartManagerWithFinalityProvider(t *testing.T) (*TestManager, *service.Fina } func (tm *TestManager) Stop(t *testing.T) { - err := tm.Fpa.Stop() - require.NoError(t, err) - err = tm.manager.ClearResources() + err := tm.manager.ClearResources() require.NoError(t, err) err = os.RemoveAll(tm.baseDir) require.NoError(t, err)