Skip to content

Commit

Permalink
Listen to initialization message instead of sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Aug 16, 2024
1 parent ba96e5f commit fa3d590
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 62 deletions.
1 change: 1 addition & 0 deletions relayer/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func main() {
)
})
}
logger.Info("Initialization complete")
err = errGroup.Wait()
logger.Error("Relayer exiting.", zap.Error(err))
}
Expand Down
1 change: 1 addition & 0 deletions signature-aggregator/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func main() {
signatureAggregator,
)

logger.Info("Initialization complete")
err = http.ListenAndServe(fmt.Sprintf(":%d", cfg.APIPort), nil)
if errors.Is(err, http.ErrServerClosed) {
logger.Info("server closed")
Expand Down
52 changes: 36 additions & 16 deletions tests/allowed_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,17 @@ func AllowedAddresses(network interfaces.LocalNetwork) {

// Test Relayer 1
log.Info("Testing Relayer 1: All sources -> All destinations")
relayerCleanup := testUtils.RunRelayerExecutable(ctx, relayerConfigPath1)
relayerCleanup, readyChan := testUtils.RunRelayerExecutable(ctx, relayerConfigPath1)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
log.Info("Waiting for the relayers to start up")
time.Sleep(10 * time.Second)
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

// Allowed by Relayer 1
testUtils.RelayBasicMessage(
Expand All @@ -196,12 +201,17 @@ func AllowedAddresses(network interfaces.LocalNetwork) {

// Test Relayer 2
log.Info("Testing Relayer 2: Specific source -> All destinations")
relayerCleanup = testUtils.RunRelayerExecutable(ctx, relayerConfigPath2)
relayerCleanup, readyChan = testUtils.RunRelayerExecutable(ctx, relayerConfigPath2)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
log.Info("Waiting for the relayers to start up")
time.Sleep(10 * time.Second)
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

// Disallowed by Relayer 2
_, _, id := testUtils.SendBasicTeleporterMessage(
Expand Down Expand Up @@ -236,12 +246,17 @@ func AllowedAddresses(network interfaces.LocalNetwork) {

// Test Relayer 3
log.Info("Testing Relayer 3: All sources -> Specific destination")
relayerCleanup = testUtils.RunRelayerExecutable(ctx, relayerConfigPath3)
relayerCleanup, readyChan = testUtils.RunRelayerExecutable(ctx, relayerConfigPath3)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
log.Info("Waiting for the relayers to start up")
time.Sleep(10 * time.Second)
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

// Disallowed by Relayer 3
_, _, id = testUtils.SendBasicTeleporterMessage(
Expand Down Expand Up @@ -276,12 +291,17 @@ func AllowedAddresses(network interfaces.LocalNetwork) {

// Test Relayer 4
log.Info("Testing Relayer 4: Specific source -> Specific destination")
relayerCleanup = testUtils.RunRelayerExecutable(ctx, relayerConfigPath4)
relayerCleanup, readyChan = testUtils.RunRelayerExecutable(ctx, relayerConfigPath4)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
log.Info("Waiting for the relayers to start up")
time.Sleep(10 * time.Second)
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

// Disallowed by Relayer 4
_, _, id = testUtils.SendBasicTeleporterMessage(
Expand Down
21 changes: 17 additions & 4 deletions tests/basic_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ func BasicRelay(network interfaces.LocalNetwork) {
log.Info("Test Relaying from Subnet A to Subnet B")

log.Info("Starting the relayer")
relayerCleanup := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
relayerCleanup, readyChan := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
time.Sleep(15 * time.Second)
select {
case <-readyChan:
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

log.Info("Sending transaction from Subnet A to Subnet B")
testUtils.RelayBasicMessage(
Expand Down Expand Up @@ -143,9 +147,18 @@ func BasicRelay(network interfaces.LocalNetwork) {

// Run the relayer
log.Info("Creating new relayer instance to test already delivered message")
relayerCleanup = testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
relayerCleanup, readyChan = testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()

// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

// We should not receive a new block on subnet B, since the relayer should have
// seen the Teleporter message was already delivered.
log.Info("Waiting for 10s to ensure no new block confirmations on destination chain")
Expand Down
11 changes: 8 additions & 3 deletions tests/batch_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ func BatchRelay(network interfaces.LocalNetwork) {
relayerConfigPath := testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname)

log.Info("Starting the relayer")
relayerCleanup := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
relayerCleanup, readyChan := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
time.Sleep(15 * time.Second)
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

//
// Send a batch message from subnet A -> B
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestE2E(t *testing.T) {
if r := recover(); r != nil {
fmt.Sprintf("Panic caught: %v", r)
cleanup()
os.Exit(1)
}
}()
// Handle SIGINT and SIGTERM signals as well.
Expand All @@ -49,6 +50,7 @@ func TestE2E(t *testing.T) {
sig := <-signalChan
fmt.Printf("Caught signal %s: Shutting down...\n", sig)
cleanup()
os.Exit(1)
}()

if os.Getenv("RUN_E2E") == "" {
Expand Down Expand Up @@ -117,12 +119,12 @@ var _ = ginkgo.BeforeSuite(func() {

decider = exec.CommandContext(ctx, "./tests/cmd/decider/decider")
decider.Start()
go func() { // panic if the decider exits abnormally
go func() {
err := decider.Wait()
// Context cancellation is the only expected way for the
// process to exit, otherwise panic
// otherwise log an error but don't panic to allow for easier cleanup
if !errors.Is(ctx.Err(), context.Canceled) {
panic(fmt.Errorf("decider exited abnormally: %w", err))
log.Error("Decider exited abnormally: ", "error", err)
}
}()
log.Info("Started decider service")
Expand All @@ -138,14 +140,13 @@ var _ = ginkgo.BeforeSuite(func() {
})

func cleanup() {
fmt.Printf("Cleaning up\n")
if localNetworkInstance != nil {
fmt.Printf("Started cleaning up\n")
localNetworkInstance.TearDownNetwork()
fmt.Printf("Finished cleaning up\n")
}
if decider != nil {
cancelDecider()
decider = nil
}
if localNetworkInstance != nil {
localNetworkInstance.TearDownNetwork()
localNetworkInstance = nil
}
}

Expand Down
10 changes: 7 additions & 3 deletions tests/manual_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ func ManualMessage(network interfaces.LocalNetwork) {
relayerConfigPath := testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname)

log.Info("Starting the relayer")
relayerCleanup := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
relayerCleanup, readyChan := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
// Wait for relayer to startup.
log.Info("Waiting for the relayer to start up")
time.Sleep(15 * time.Second)
select {
case <-readyChan:
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

reqBody := api.ManualWarpMessageRequest{
UnsignedMessageBytes: unsignedMessage.Bytes(),
Expand Down
11 changes: 8 additions & 3 deletions tests/relay_message_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ func RelayMessageAPI(network interfaces.LocalNetwork) {
relayerConfigPath := testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname)

log.Info("Starting the relayer")
relayerCleanup := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
relayerCleanup, readyChan := testUtils.RunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()

// Sleep for some time to make sure relayer has started up and subscribed.
// Wait for relayer to start up
log.Info("Waiting for the relayer to start up")
time.Sleep(15 * time.Second)
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Relayer did not start up in time")
}

reqBody := api.RelayMessageRequest{
BlockchainID: subnetAInfo.BlockchainID.String(),
Expand Down
14 changes: 9 additions & 5 deletions tests/shared_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tests

import (
"context"
"time"
"sync"

testUtils "github.com/ava-labs/awm-relayer/tests/utils"
"github.com/ava-labs/teleporter/tests/interfaces"
Expand Down Expand Up @@ -68,14 +68,18 @@ func SharedDatabaseAccess(network interfaces.LocalNetwork) {
log.Info("Test Relaying from Subnet A to Subnet B")

log.Info("Starting the relayers")
relayerCleanupA := testUtils.RunRelayerExecutable(ctx, relayerConfigPathA)
relayerCleanupA, readyChanA := testUtils.RunRelayerExecutable(ctx, relayerConfigPathA)
defer relayerCleanupA()
relayerCleanupB := testUtils.RunRelayerExecutable(ctx, relayerConfigPathB)
relayerCleanupB, readyChanB := testUtils.RunRelayerExecutable(ctx, relayerConfigPathB)
defer relayerCleanupB()

// Sleep for some time to make sure relayer has started up and subscribed.
// Wait for the relayers to start up
log.Info("Waiting for the relayers to start up")
time.Sleep(15 * time.Second)
var wg sync.WaitGroup
wg.Add(2)
go testUtils.WaitFunc(&wg, readyChanA)
go testUtils.WaitFunc(&wg, readyChanB)
wg.Wait()

log.Info("Sending transaction from Subnet A to Subnet B")
testUtils.RelayBasicMessage(
Expand Down
13 changes: 9 additions & 4 deletions tests/signature_aggregator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) {
testUtils.DefaultSignatureAggregatorCfgFname,
)
log.Info("Starting the signature aggregator", "configPath", signatureAggregatorConfigPath)
signatureAggregatorCancel := testUtils.RunSignatureAggregatorExecutable(ctx, signatureAggregatorConfigPath)
signatureAggregatorCancel, readyChan := testUtils.RunSignatureAggregatorExecutable(ctx, signatureAggregatorConfigPath)
defer signatureAggregatorCancel()

// Sleep for some time to make sure signature aggregator has started up and subscribed.
log.Info("Waiting for the signature aggregator to start up")
time.Sleep(5 * time.Second)
// Wait for signature-aggregator to start up
log.Info("Waiting for the relayer to start up")
select {
case <-readyChan:
close(readyChan)
case <-time.After(15 * time.Second):
Expect(false).To(BeTrue(), "Signature Aggregator did not start up in time")
}

// End setup step
// Begin Test Case 1
Expand Down
Loading

0 comments on commit fa3d590

Please sign in to comment.