2022-05-18 16:12:54 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2022 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-04-22 16:27:54 +00:00
|
|
|
package boot_test
|
|
|
|
|
|
|
|
import (
|
2022-04-26 17:57:01 +00:00
|
|
|
"context"
|
|
|
|
|
2022-04-22 16:27:54 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
2022-06-09 21:32:46 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-beacon-indexer/internal/boot"
|
2022-04-22 16:27:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Boot", func() {
|
|
|
|
var (
|
2022-09-29 01:39:56 +00:00
|
|
|
dbAddress string = "localhost"
|
|
|
|
dbPort int = 8076
|
|
|
|
dbName string = "vulcanize_testing"
|
|
|
|
dbUsername string = "vdbm"
|
|
|
|
dbPassword string = "password"
|
|
|
|
dbDriver string = "PGX"
|
|
|
|
bcAddress string = "localhost"
|
|
|
|
bcPort int = 5052
|
|
|
|
bcConnectionProtocol string = "http"
|
|
|
|
bcType string = "lighthouse"
|
|
|
|
bcBootRetryInterval int = 1
|
|
|
|
bcBootMaxRetry int = 5
|
|
|
|
bcKgTableIncrement int = 10
|
|
|
|
bcUniqueIdentifier int = 100
|
|
|
|
bcCheckDb bool = false
|
|
|
|
bcProcessBeaconBlocks bool = true
|
|
|
|
bcProcessBeaconState bool = true
|
2022-04-22 16:27:54 +00:00
|
|
|
)
|
|
|
|
Describe("Booting the application", Label("integration"), func() {
|
2022-05-19 13:46:38 +00:00
|
|
|
Context("When the DB and BC are both up and running, we skip checking for a synced head, and we are processing head", func() {
|
2022-04-22 16:27:54 +00:00
|
|
|
It("Should connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, db, err := boot.BootApplicationWithRetry(context.Background(), dbAddress, dbPort, dbName, dbUsername, dbPassword, dbDriver, bcAddress, bcPort, bcConnectionProtocol, bcType, bcBootRetryInterval, bcBootMaxRetry, bcKgTableIncrement, "head", true, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-05-19 13:46:38 +00:00
|
|
|
defer db.Close()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When the DB and BC are both up and running, we skip checking for a synced head, and we are processing historic ", func() {
|
|
|
|
It("Should connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, db, err := boot.BootApplicationWithRetry(context.Background(), dbAddress, dbPort, dbName, dbUsername, dbPassword, dbDriver, bcAddress, bcPort, bcConnectionProtocol, bcType, bcBootRetryInterval, bcBootMaxRetry, bcKgTableIncrement, "historic", true, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-04-22 16:27:54 +00:00
|
|
|
defer db.Close()
|
2022-05-13 12:48:31 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When the DB and BC are both up and running, and we check for a synced head", func() {
|
|
|
|
It("Should not connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, db, err := boot.BootApplicationWithRetry(context.Background(), dbAddress, dbPort, dbName, dbUsername, dbPassword, dbDriver, bcAddress, bcPort, bcConnectionProtocol, bcType, bcBootRetryInterval, bcBootMaxRetry, bcKgTableIncrement, "head", false, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-06-03 16:47:13 +00:00
|
|
|
defer db.Close()
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When the DB and BC are both up and running, we skip checking for a synced head, but the unique identifier is 0", func() {
|
|
|
|
It("Should not connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, db, err := boot.BootApplicationWithRetry(context.Background(), dbAddress, dbPort, dbName, dbUsername, dbPassword, dbDriver, bcAddress, bcPort, bcConnectionProtocol, bcType, bcBootRetryInterval, bcBootMaxRetry, bcKgTableIncrement, "head", false, 0, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-05-13 12:48:31 +00:00
|
|
|
defer db.Close()
|
|
|
|
Expect(err).To(HaveOccurred())
|
2022-04-22 16:27:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When the DB is running but not the BC", func() {
|
|
|
|
It("Should not connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, _, err := boot.BootApplication(context.Background(), dbAddress, dbPort, dbName, dbUsername, dbPassword, dbDriver, "hi", 100, bcConnectionProtocol, bcKgTableIncrement, true, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-05-13 12:48:31 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2022-04-22 16:27:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When the BC is running but not the DB", func() {
|
|
|
|
It("Should not connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, _, err := boot.BootApplication(context.Background(), "hi", 10, dbName, dbUsername, dbPassword, dbDriver, bcAddress, bcPort, bcConnectionProtocol, bcKgTableIncrement, true, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-05-13 12:48:31 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2022-04-22 16:27:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
Context("When neither the BC or DB are running", func() {
|
|
|
|
It("Should not connect successfully", func() {
|
2022-09-29 01:39:56 +00:00
|
|
|
_, _, err := boot.BootApplication(context.Background(), "hi", 10, dbName, dbUsername, dbPassword, dbDriver, "hi", 100, bcConnectionProtocol, bcKgTableIncrement, true, bcUniqueIdentifier, bcCheckDb, bcProcessBeaconBlocks, bcProcessBeaconState)
|
2022-05-13 12:48:31 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2022-04-22 16:27:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|