Ensure we release locks properly

This commit is contained in:
Abdul Rabbani 2022-06-08 11:54:29 -04:00
parent d9d20ed922
commit 9d8f5bc6eb
3 changed files with 22 additions and 4 deletions

View File

@ -11,6 +11,12 @@ import (
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/beaconclient"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
)
var (
kgCheckCheckedOutStmt = `SELECT * FROM ethcl.known_gaps WHERE checked_out=true `
hpCheckCheckedOutStmt = `SELECT * FROM ethcl.historic_process WHERE checked_out=true `
)
var _ = Describe("Capturehistoric", func() {
@ -137,8 +143,9 @@ func (tbc TestBeaconNode) runHistoricalProcess(bc *beaconclient.BeaconClient, ma
validateMetrics(bc, expectedInserts, expectedReorgs, expectedKnownGaps, expectedKnownGapsReprocessError)
log.Debug("Calling the stop function for historical processing..")
err := bc.StopHistoric(cancel)
time.Sleep(5 * time.Second)
Expect(err).ToNot(HaveOccurred())
time.Sleep(3 * time.Second)
validateAllRowsCheckedOut(bc.Db, hpCheckCheckedOutStmt)
}
// Wrapper function that processes knownGaps
@ -147,8 +154,9 @@ func (tbc TestBeaconNode) runKnownGapsProcess(bc *beaconclient.BeaconClient, max
go bc.ProcessKnownGaps(ctx, maxWorkers)
validateMetrics(bc, expectedInserts, expectedReorgs, expectedKnownGaps, expectedKnownGapsReprocessError)
err := bc.StopKnownGapsProcessing(cancel)
time.Sleep(5 * time.Second)
Expect(err).ToNot(HaveOccurred())
time.Sleep(3 * time.Second)
validateAllRowsCheckedOut(bc.Db, kgCheckCheckedOutStmt)
}
func validateMetrics(bc *beaconclient.BeaconClient, expectedInserts, expectedReorgs, expectedKnownGaps, expectedKnownGapsReprocessError uint64) {
@ -209,3 +217,13 @@ func validatePopularBatchBlocks(bc *beaconclient.BeaconClient) {
validateSignedBeaconBlock(bc, BeaconNodeTester.TestEvents["2375703"].HeadMessage, BeaconNodeTester.TestEvents["2375703"].CorrectParentRoot, BeaconNodeTester.TestEvents["2375703"].CorrectEth1BlockHash, BeaconNodeTester.TestEvents["2375703"].CorrectSignedBeaconBlockMhKey)
validateBeaconState(bc, BeaconNodeTester.TestEvents["2375703"].HeadMessage, BeaconNodeTester.TestEvents["2375703"].CorrectBeaconStateMhKey)
}
// Make sure all rows have checked_out as false.
func validateAllRowsCheckedOut(db sql.Database, checkStmt string) {
res, err := db.Exec(context.Background(), checkStmt)
Expect(err).ToNot(HaveOccurred())
rows, err := res.RowsAffected()
log.Info("rows: ", rows)
Expect(err).ToNot(HaveOccurred())
Expect(rows).To(Equal(int64(0)))
}

View File

@ -47,7 +47,7 @@ var (
WHERE start_slot=$1 AND end_slot=$2;`
// Used to update every single row that this node has checked out.
releaseHpLockStmt string = `UPDATE ethcl.historic_process
SET checked_out=false
SET checked_out=false, checked_out_by=null
WHERE checked_out_by=$1`
)

View File

@ -46,7 +46,7 @@ var (
WHERE start_slot=$1 AND end_slot=$2;`
// Used to update every single row that this node has checked out.
releaseKgLockStmt string = `UPDATE ethcl.known_gaps
SET checked_out=false
SET checked_out=false, checked_out_by=null
WHERE checked_out_by=$1`
)