generated from ethereum-optimism/.github
-
Notifications
You must be signed in to change notification settings - Fork 60
fix(op-acceptor): add build dependencies and increase logs #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
serpixel
wants to merge
8
commits into
main
Choose a base branch
from
fix/op-acceptor/ensure-package-paths-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5a3506f
fix(op-acceptor): ensure package paths are valid, increase timeouts
serpixel d35c624
fix(op-acceptor): add extra logs and increase timeout
serpixel 9083dfd
fix(op-acceptor): switch to go base image and add build tools
serpixel f588c27
feat(op-acceptor): add extended logging
serpixel 5695367
fix(op-acceptor): failing test
serpixel 1663761
fix(op-acceptor): parse output
serpixel ca75ba0
fix(op-acceptor): comments
serpixel ea905aa
fix(op-acceptor): add extra tests
serpixel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,8 @@ package runner | |||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"context" | ||||||||||||||
"os" | ||||||||||||||
"path/filepath" | ||||||||||||||
"testing" | ||||||||||||||
|
||||||||||||||
"github.com/ethereum-optimism/infra/op-acceptor/types" | ||||||||||||||
|
@@ -68,3 +70,133 @@ gates: | |||||||||||||
assert.Contains(t, failingTest.Stdout, "This is some stdout output that should be captured") | ||||||||||||||
assert.Contains(t, failingTest.Stdout, "This is a second line of output") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// TestLogLevelEnvironment verifies that the TEST_LOG_LEVEL environment variable is correctly set and used | ||||||||||||||
func TestLogLevelEnvironment(t *testing.T) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also test the different levels behave differently? |
||||||||||||||
ctx := context.Background() | ||||||||||||||
|
||||||||||||||
// Create a simple test file in the work directory | ||||||||||||||
testContent := []byte(` | ||||||||||||||
package main | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"os" | ||||||||||||||
"testing" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
func TestLogLevelEnvironment(t *testing.T) { | ||||||||||||||
// Get log level from environment | ||||||||||||||
logLevel := os.Getenv("TEST_LOG_LEVEL") | ||||||||||||||
if logLevel == "" { | ||||||||||||||
t.Log("TEST_LOG_LEVEL not set") | ||||||||||||||
} else { | ||||||||||||||
t.Log("TEST_LOG_LEVEL set to", logLevel) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
`) | ||||||||||||||
configContent := []byte(` | ||||||||||||||
gates: | ||||||||||||||
- id: logging-gate | ||||||||||||||
description: "Gate with a test that outputs logs" | ||||||||||||||
suites: | ||||||||||||||
logging-suite: | ||||||||||||||
description: "Suite with a test that outputs logs" | ||||||||||||||
tests: | ||||||||||||||
- name: TestLogLevelEnvironment | ||||||||||||||
package: "./main" | ||||||||||||||
`) | ||||||||||||||
|
||||||||||||||
r := setupTestRunner(t, testContent, configContent) | ||||||||||||||
r.testLogLevel = "debug" | ||||||||||||||
err := os.WriteFile(filepath.Join(r.workDir, "main_test.go"), testContent, 0644) | ||||||||||||||
require.NoError(t, err) | ||||||||||||||
|
||||||||||||||
result, err := r.RunTest(ctx, types.ValidatorMetadata{ | ||||||||||||||
ID: "test1", | ||||||||||||||
Gate: "logging-gate", | ||||||||||||||
FuncName: "TestLogLevelEnvironment", | ||||||||||||||
Package: ".", | ||||||||||||||
}) | ||||||||||||||
|
||||||||||||||
require.NoError(t, err) | ||||||||||||||
assert.Equal(t, types.TestStatusPass, result.Status) | ||||||||||||||
assert.Equal(t, "test1", result.Metadata.ID) | ||||||||||||||
assert.Equal(t, "logging-gate", result.Metadata.Gate) | ||||||||||||||
assert.Equal(t, ".", result.Metadata.Package) | ||||||||||||||
assert.False(t, result.Metadata.RunAll) | ||||||||||||||
assert.Contains(t, result.Stdout, "TEST_LOG_LEVEL set to debug") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// TestOutputTestLogs verifies that test logs are properly captured and output when enabled | ||||||||||||||
func TestOutputTestLogs(t *testing.T) { | ||||||||||||||
// Create a test file that outputs logs at different levels | ||||||||||||||
testContent := []byte(` | ||||||||||||||
package feature_test | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"testing" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
func TestWithLogs(t *testing.T) { | ||||||||||||||
t.Log("This is a test output") | ||||||||||||||
} | ||||||||||||||
`) | ||||||||||||||
|
||||||||||||||
configContent := []byte(` | ||||||||||||||
gates: | ||||||||||||||
- id: logging-gate | ||||||||||||||
description: "Gate with a test that outputs logs" | ||||||||||||||
suites: | ||||||||||||||
logging-suite: | ||||||||||||||
description: "Suite with a test that outputs logs" | ||||||||||||||
tests: | ||||||||||||||
- name: TestWithLogs | ||||||||||||||
package: "./feature" | ||||||||||||||
`) | ||||||||||||||
|
||||||||||||||
// Setup the test runner with OutputTestLogs enabled | ||||||||||||||
r := setupTestRunner(t, testContent, configContent) | ||||||||||||||
r.outputTestLogs = true | ||||||||||||||
|
||||||||||||||
// Run the test | ||||||||||||||
result, err := r.RunAllTests(context.Background()) | ||||||||||||||
require.NoError(t, err) | ||||||||||||||
assert.Equal(t, types.TestStatusPass, result.Status) | ||||||||||||||
|
||||||||||||||
// Verify the structure | ||||||||||||||
require.Contains(t, result.Gates, "logging-gate") | ||||||||||||||
gate := result.Gates["logging-gate"] | ||||||||||||||
require.Contains(t, gate.Suites, "logging-suite") | ||||||||||||||
suite := gate.Suites["logging-suite"] | ||||||||||||||
|
||||||||||||||
// Get the test result | ||||||||||||||
var testResult *types.TestResult | ||||||||||||||
for _, test := range suite.Tests { | ||||||||||||||
testResult = test | ||||||||||||||
break | ||||||||||||||
} | ||||||||||||||
require.NotNil(t, testResult) | ||||||||||||||
|
||||||||||||||
// Verify the test passed and has logs captured | ||||||||||||||
assert.Equal(t, types.TestStatusPass, testResult.Status) | ||||||||||||||
assert.NotEmpty(t, testResult.Stdout) | ||||||||||||||
assert.Contains(t, testResult.Stdout, "This is a test output") | ||||||||||||||
|
||||||||||||||
// Now run with OutputTestLogs disabled | ||||||||||||||
r.outputTestLogs = false | ||||||||||||||
result, err = r.RunAllTests(context.Background()) | ||||||||||||||
require.NoError(t, err) | ||||||||||||||
assert.Equal(t, types.TestStatusPass, result.Status) | ||||||||||||||
|
||||||||||||||
// Get the test result again | ||||||||||||||
var testResult2 *types.TestResult | ||||||||||||||
for _, test := range result.Gates["logging-gate"].Suites["logging-suite"].Tests { | ||||||||||||||
testResult2 = test | ||||||||||||||
break | ||||||||||||||
} | ||||||||||||||
require.NotNil(t, testResult) | ||||||||||||||
|
||||||||||||||
// Verify that logs are not captured when OutputTestLogs is disabled | ||||||||||||||
assert.Equal(t, types.TestStatusPass, testResult2.Status) | ||||||||||||||
assert.Contains(t, testResult2.Stdout, "This is a test output") | ||||||||||||||
Comment on lines
+199
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be asserting that it does NOT contain this output?
Suggested change
|
||||||||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? The logs and files are working without this, I believe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed if running the docker image locally unless we change the directory we run it on (like in CI).