From 6cecc69520121a4a019bfb0a8aba13b2a6855c6a Mon Sep 17 00:00:00 2001 From: Abdul Rabbani Date: Wed, 22 Jun 2022 14:09:39 -0400 Subject: [PATCH] Don't close DB --- pkg/beaconclient/capturehead_test.go | 19 ++++++++++++------- pkg/beaconclient/capturehistoric_test.go | 10 ++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/beaconclient/capturehead_test.go b/pkg/beaconclient/capturehead_test.go index cc75ebd..2932da8 100644 --- a/pkg/beaconclient/capturehead_test.go +++ b/pkg/beaconclient/capturehead_test.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "runtime" + "runtime/pprof" "strconv" "sync/atomic" "time" @@ -265,8 +266,8 @@ type MimicConfig struct { var _ = Describe("Capturehead", Label("head"), func() { Describe("Receiving New Head SSE messages", Label("unit", "behavioral"), func() { - Context("Correctly formatted Phase0 Block", Label("leak-head"), func() { - It("Should turn it into a struct successfully.", func() { + Context("Correctly formatted Phase0 Block", func() { + It("Should process it successfully.", func() { BeaconNodeTester.SetupBeaconNodeMock(BeaconNodeTester.TestEvents, BeaconNodeTester.TestConfig.protocol, BeaconNodeTester.TestConfig.address, BeaconNodeTester.TestConfig.port, BeaconNodeTester.TestConfig.dummyParentRoot) defer httpmock.DeactivateAndReset() bc := setUpTest(BeaconNodeTester.TestConfig, "99") @@ -277,8 +278,9 @@ var _ = Describe("Capturehead", Label("head"), func() { }) }) - Context("Correctly formatted Altair Block", func() { - It("Should turn it into a struct successfully.", func() { + Context("Correctly formatted Altair Block", Label("leak-head"), func() { + It("Should process it successfully.", func() { + log.SetLevel(log.DebugLevel) BeaconNodeTester.SetupBeaconNodeMock(BeaconNodeTester.TestEvents, BeaconNodeTester.TestConfig.protocol, BeaconNodeTester.TestConfig.address, BeaconNodeTester.TestConfig.port, BeaconNodeTester.TestConfig.dummyParentRoot) defer httpmock.DeactivateAndReset() @@ -917,6 +919,7 @@ func (tbc TestBeaconNode) testMultipleReorgs(bc *beaconclient.BeaconClient, firs // A test to validate a single block was processed correctly func (tbc TestBeaconNode) testProcessBlock(bc *beaconclient.BeaconClient, head beaconclient.Head, epoch int, maxRetry int, expectedSuccessInsert uint64, expectedKnownGaps uint64, expectedReorgs uint64) { + pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) startGoRoutines := runtime.NumGoroutine() ctx, cancel := context.WithCancel(context.Background()) go bc.CaptureHead(ctx, 2, true) @@ -1030,11 +1033,13 @@ func testSszRoot(msg Message) { // A make shift function to stop head tracking and insure we dont have any goroutine leaks func testStopHeadTracking(ctx context.Context, bc *beaconclient.BeaconClient, startGoRoutines int) { - bc.Db.Close() bc.StopHeadTracking(ctx, true) time.Sleep(3 * time.Second) endNum := runtime.NumGoroutine() - //pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - Expect(startGoRoutines).To(Equal(endNum)) + pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) + log.WithField("startNum", startGoRoutines).Info("Start Go routine number") + log.WithField("endNum", endNum).Info("End Go routine number") + //Expect(endNum <= startGoRoutines).To(BeTrue()) + Expect(endNum).To(Equal(startGoRoutines)) } diff --git a/pkg/beaconclient/capturehistoric_test.go b/pkg/beaconclient/capturehistoric_test.go index 54e1a3c..faef10b 100644 --- a/pkg/beaconclient/capturehistoric_test.go +++ b/pkg/beaconclient/capturehistoric_test.go @@ -305,14 +305,13 @@ func testStopHistoricProcessing(ctx context.Context, bc *beaconclient.BeaconClie Expect(err).ToNot(HaveOccurred()) time.Sleep(5 * time.Second) validateAllRowsCheckedOut(bc.Db, hpCheckCheckedOutStmt) - err = bc.Db.Close() - Expect(err).ToNot(HaveOccurred()) time.Sleep(3 * time.Second) endNum := runtime.NumGoroutine() //pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - Expect(startGoRoutines).To(Equal(endNum)) + //Expect(endNum <= startGoRoutines).To(BeTrue()) + Expect(endNum).To(Equal(startGoRoutines)) } // A make shift function to stop head tracking and insure we dont have any goroutine leaks @@ -322,12 +321,11 @@ func testStopKnownGapProcessing(ctx context.Context, bc *beaconclient.BeaconClie Expect(err).ToNot(HaveOccurred()) time.Sleep(5 * time.Second) validateAllRowsCheckedOut(bc.Db, kgCheckCheckedOutStmt) - err = bc.Db.Close() - Expect(err).ToNot(HaveOccurred()) time.Sleep(3 * time.Second) endNum := runtime.NumGoroutine() //pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - Expect(startGoRoutines).To(Equal(endNum)) + //Expect(endNum <= startGoRoutines).To(BeTrue()) + Expect(endNum).To(Equal(startGoRoutines)) }