Skip to content
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

Fix deferred cleanup structure in TestMain function #1542

Open
Favy217 opened this issue Oct 17, 2024 · 0 comments
Open

Fix deferred cleanup structure in TestMain function #1542

Favy217 opened this issue Oct 17, 2024 · 0 comments

Comments

@Favy217
Copy link

Favy217 commented Oct 17, 2024

Problem

The current TestMain function in tests/bridge_test.go calls m.Run() after a deferred cleanup block, which prevents the deferred functions from executing correctly. This needs to be updated to ensure proper cleanup after the tests finish running.

Code to Fix

The following code is found in tests/test_file.go, starting at line 47:

func TestMain(m *testing.M) {
    defer func() {
        if testApps != nil {
            testApps.Free()
        }
        if rollupApp != nil {
            rollupApp.Free()
        }
    }()
    m.Run()
}
__________________________________________________________________________________-
Suggested Solution

Move the m.Run() before the defer block, as follows:

func TestMain(m *testing.M) {
    code := m.Run()  // Call before defer
    defer func() {
        if testApps != nil {
            testApps.Free()
        }
        if rollupApp != nil {
            rollupApp.Free()
        }
    }()
    os.Exit(code)  // Properly exits with test results
}
Favy217 pushed a commit to Favy217/scroll that referenced this issue Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant