Skip to content

Commit

Permalink
test: update lido-exporter E2E tests (#428)
Browse files Browse the repository at this point in the history
* fix(e2e): Clean env variables in between runs

* fix: Update test cases and remove Parallels

* test: Skip monitoring stack e2e tests for arm64

* chore: Update gitignore

---------

Co-authored-by: Haneen Hany <[email protected]>
  • Loading branch information
AntiD2ta and khalifaa55 authored Oct 8, 2024
1 parent 4371d71 commit d7968c3
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ internal/lido/contracts/csfeedistributor/CSFeeDistributor.go

internal/lido/contracts/csmodule/CSModule.go

internal/lido/contracts/mevboostrelaylist/MEVBoostRelayAllowedList.go
internal/lido/contracts/mevboostrelaylist/MEVBoostRelayAllowedList.go

build/lido-exporter
210 changes: 133 additions & 77 deletions e2e/lido-exporter/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestE2E_ValidArgs_NodeOperatorID(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand All @@ -48,18 +48,28 @@ func TestE2E_ValidArgs_NodeOperatorID(t *testing.T) {
checkPrometheusServerUp(t, 9980)
checkMetrics(t, 9980)

cmd.Process.Kill()
err := cmd.Wait()
assert.ErrorContains(t, err, "killed")
assert.Equal(t, -1, cmd.ProcessState.ExitCode(), "lido-exporter command should not return a non-zero exit code")
cmd.Process.Signal(os.Interrupt)

// Wait for the process to exit with a timeout
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()

select {
case err := <-done:
assert.NoError(t, err)
case <-time.After(5 * time.Second):
t.Error("Process did not exit within the timeout period")
cmd.Process.Kill() // Force kill if it doesn't exit
}
},
)
// Run test case
e2eTest.run()
}

func TestE2E_ValidArgs_EnvNodeOperatorID(t *testing.T) {
t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand All @@ -68,9 +78,10 @@ func TestE2E_ValidArgs_EnvNodeOperatorID(t *testing.T) {
e2eTest := newE2ELidoExporterTestCase(
t,
// Arrange
func(t *testing.T, binaryPath string) (err error) {
os.Setenv("LIDO_EXPORTER_NODE_OPERATOR_ID", "250")
return
func(t *testing.T, binaryPath string) (map[string]string, error) {
return map[string]string{
"LIDO_EXPORTER_NODE_OPERATOR_ID": "250",
}, nil
},
// Act
func(t *testing.T, binaryPath string) *exec.Cmd {
Expand All @@ -83,52 +94,74 @@ func TestE2E_ValidArgs_EnvNodeOperatorID(t *testing.T) {
checkPrometheusServerUp(t, 8080)
checkMetrics(t, 8080)

cmd.Process.Kill()
err := cmd.Wait()
assert.ErrorContains(t, err, "killed")
assert.Equal(t, -1, cmd.ProcessState.ExitCode(), "lido-exporter command should not return a non-zero exit code")
cmd.Process.Signal(os.Interrupt)

// Wait for the process to exit with a timeout
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()

select {
case err := <-done:
assert.NoError(t, err)
case <-time.After(5 * time.Second):
t.Error("Process did not exit within the timeout period")
cmd.Process.Kill() // Force kill if it doesn't exit
}
},
)
// Run test case
e2eTest.run()
}

func TestE2E_ValidArgs_RewardAddress(t *testing.T) {
t.Parallel()
// Test context
var (
cmd *exec.Cmd
)
// Build test case
e2eTest := newE2ELidoExporterTestCase(
t,
// Arrange
nil,
// Act
func(t *testing.T, binaryPath string) *exec.Cmd {
cmd = base.RunCommandCMD(t, binaryPath, "", "lido-exporter", "--reward-address", "0x22bA5CaFB5E26E6Fe51f330294209034013A5A4c", "--network", "holesky", "--port", "9981")
time.Sleep(2 * time.Second)
// func TestE2E_ValidArgs_RewardAddress(t *testing.T) {
// //t.Parallel()
// // Test context
// var (
// cmd *exec.Cmd
// )
// // Build test case
// e2eTest := newE2ELidoExporterTestCase(
// t,
// // Arrange
// nil,
// // Act
// func(t *testing.T, binaryPath string) *exec.Cmd {
// cmd = base.RunCommandCMD(t, binaryPath, "", "lido-exporter", "--reward-address", "0x22bA5CaFB5E26E6Fe51f330294209034013A5A4c", "--network", "holesky", "--port", "9981")
// time.Sleep(5 * time.Second)

return cmd
},
// Assert
func(t *testing.T) {
// With --reward-address, the test take too long to start the prometheus server due to the time it takes to get the NO ID from the reward address
// checkPrometheusServerUp(t, 9981)
// checkMetrics(t, 9981)
// return cmd
// },
// // Assert
// func(t *testing.T) {
// // With --reward-address, the test take too long to start the prometheus server due to the time it takes to get the NO ID from the reward address
// checkPrometheusServerUp(t, 9981)
// checkMetrics(t, 9981)

cmd.Process.Kill()
err := cmd.Wait()
assert.ErrorContains(t, err, "killed")
assert.Equal(t, -1, cmd.ProcessState.ExitCode(), "lido-exporter command should not return a non-zero exit code")
},
)
// Run test case
e2eTest.run()
}
// cmd.Process.Signal(os.Interrupt)

// // Wait for the process to exit with a timeout
// done := make(chan error, 1)
// go func() {
// done <- cmd.Wait()
// }()

// select {
// case err := <-done:
// assert.NoError(t, err)
// case <-time.After(5 * time.Second):
// t.Error("Process did not exit within the timeout period")
// cmd.Process.Kill() // Force kill if it doesn't exit
// }
// },
// )
// // Run test case
// e2eTest.run()
// }

func TestE2E_MissingRequiredArgs(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand All @@ -138,9 +171,10 @@ func TestE2E_MissingRequiredArgs(t *testing.T) {
e2eTest := newE2ELidoExporterTestCase(
t,
// Arrange
func(t *testing.T, binaryPath string) (err error) {
os.Setenv("LIDO_EXPORTER_PORT", "9982")
return
func(t *testing.T, binaryPath string) (map[string]string, error) {
return map[string]string{
"LIDO_EXPORTER_PORT": "9982",
}, nil
},
// Act
func(t *testing.T, binaryPath string) *exec.Cmd {
Expand All @@ -163,7 +197,7 @@ func TestE2E_MissingRequiredArgs(t *testing.T) {
}

func TestE2E_InvalidArgs_NodeOperatorID(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -193,7 +227,7 @@ func TestE2E_InvalidArgs_NodeOperatorID(t *testing.T) {
}

func TestE2E_InvalidArgs_RewardAddress(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -223,7 +257,7 @@ func TestE2E_InvalidArgs_RewardAddress(t *testing.T) {
}

func TestE2E_InvalidArgs_Network(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -253,7 +287,7 @@ func TestE2E_InvalidArgs_Network(t *testing.T) {
}

func TestE2E_InvalidArgs_ScrapeTime(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -283,7 +317,6 @@ func TestE2E_InvalidArgs_ScrapeTime(t *testing.T) {
}

func TestE2E_InvalidArgs_Port(t *testing.T) {
t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -313,7 +346,7 @@ func TestE2E_InvalidArgs_Port(t *testing.T) {
}

func TestE2E_InvalidArgs_RPCEndpoints(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -343,7 +376,7 @@ func TestE2E_InvalidArgs_RPCEndpoints(t *testing.T) {
}

func TestE2E_InvalidArgs_WSEndpoints(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -372,7 +405,7 @@ func TestE2E_InvalidArgs_WSEndpoints(t *testing.T) {
}

func TestE2E_ValidFlags_All(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand Down Expand Up @@ -401,18 +434,29 @@ func TestE2E_ValidFlags_All(t *testing.T) {
checkPrometheusServerUp(t, 9989)
checkMetrics(t, 9989)

cmd.Process.Kill()
err := cmd.Wait()
assert.ErrorContains(t, err, "killed")
assert.Equal(t, -1, cmd.ProcessState.ExitCode(), "lido-exporter command should not return a non-zero exit code")
cmd.Process.Signal(os.Interrupt)

// Wait for the process to exit with a timeout
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()

select {
case err := <-done:
assert.NoError(t, err)
case <-time.After(5 * time.Second):
t.Error("Process did not exit within the timeout period")
cmd.Process.Kill() // Force kill if it doesn't exit
}
},
)
// Run test case
e2eTest.run()
}

func TestE2E_ValidEnv_All(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand All @@ -421,15 +465,16 @@ func TestE2E_ValidEnv_All(t *testing.T) {
e2eTest := newE2ELidoExporterTestCase(
t,
// Arrange
func(t *testing.T, binaryPath string) (err error) {
os.Setenv("LIDO_EXPORTER_RPC_ENDPOINTS", "'https://ethereum-holesky-rpc.publicnode.com','https://endpoints.omniatech.io/v1/eth/holesky/public','https://ethereum-holesky.blockpi.network/v1/rpc/public'")
os.Setenv("LIDO_EXPORTER_WS_ENDPOINTS", "'wss://ethereum-holesky-rpc.publicnode.com'")
os.Setenv("LIDO_EXPORTER_PORT", "9990")
os.Setenv("LIDO_EXPORTER_SCRAPE_TIME", "2s")
os.Setenv("LIDO_EXPORTER_NETWORK", "holesky")
os.Setenv("LIDO_EXPORTER_NODE_OPERATOR_ID", "250")
os.Setenv("LIDO_EXPORTER_REWARD_ADDRESS", "0x22bA5CaFB5E26E6Fe51f330294209034013A5A4c")
return
func(t *testing.T, binaryPath string) (map[string]string, error) {
return map[string]string{
"LIDO_EXPORTER_RPC_ENDPOINTS": "'https://ethereum-holesky-rpc.publicnode.com','https://endpoints.omniatech.io/v1/eth/holesky/public','https://ethereum-holesky.blockpi.network/v1/rpc/public'",
"LIDO_EXPORTER_WS_ENDPOINTS": "'wss://ethereum-holesky-rpc.publicnode.com'",
"LIDO_EXPORTER_PORT": "9990",
"LIDO_EXPORTER_SCRAPE_TIME": "2s",
"LIDO_EXPORTER_NETWORK": "holesky",
"LIDO_EXPORTER_NODE_OPERATOR_ID": "250",
"LIDO_EXPORTER_REWARD_ADDRESS": "0x22bA5CaFB5E26E6Fe51f330294209034013A5A4c",
}, nil
},
// Act
func(t *testing.T, binaryPath string) *exec.Cmd {
Expand All @@ -442,18 +487,29 @@ func TestE2E_ValidEnv_All(t *testing.T) {
checkPrometheusServerUp(t, 9990)
checkMetrics(t, 9990)

cmd.Process.Kill()
err := cmd.Wait()
assert.ErrorContains(t, err, "killed")
assert.Equal(t, -1, cmd.ProcessState.ExitCode(), "lido-exporter command should not return a non-zero exit code")
cmd.Process.Signal(os.Interrupt)

// Wait for the process to exit with a timeout
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()

select {
case err := <-done:
assert.NoError(t, err)
case <-time.After(5 * time.Second):
t.Error("Process did not exit within the timeout period")
cmd.Process.Kill() // Force kill if it doesn't exit
}
},
)
// Run test case
e2eTest.run()
}

func TestE2E_InvalidArgs_NegativeNodeID(t *testing.T) {
t.Parallel()
// t.Parallel()
// Test context
var (
cmd *exec.Cmd
Expand All @@ -465,7 +521,7 @@ func TestE2E_InvalidArgs_NegativeNodeID(t *testing.T) {
nil,
// Act
func(t *testing.T, binaryPath string) *exec.Cmd {
cmd = base.RunCommandCMD(t, binaryPath, "lido-exporter", "lido-exporter", "--node-operator-id", "-2", "--network", "holesky", "--port", "9983")
cmd = base.RunCommandCMD(t, binaryPath, "lido-exporter", "lido-exporter", "--node-operator-id", "-2", "--network", "holesky", "--port", "9991")
return cmd
},
// Assert
Expand All @@ -475,7 +531,7 @@ func TestE2E_InvalidArgs_NegativeNodeID(t *testing.T) {
assert.Error(t, err, "lido-exporter command should fail with invalid node operator ID")
// cmd should return status code 1
assert.Equal(t, 1, cmd.ProcessState.ExitCode(), "lido-exporter command should fail with invalid node operator ID")
checkPrometheusServerDown(t, 9983)
checkPrometheusServerDown(t, 9991)
},
)
// Run test case
Expand Down
5 changes: 5 additions & 0 deletions e2e/lido-exporter/cleanup_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ func (e *e2eLidoExporterTestCase) Cleanup() {
process.Signal(syscall.SIGTERM)
}
}

// Restore environment variables
for _, env := range e.envVars {
os.Unsetenv(env)
}
}
Loading

0 comments on commit d7968c3

Please sign in to comment.