Skip to content

Fix deferred cleanup structure in TestMain function #1542

Open
@Favy217

Description

@Favy217

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions