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

test: Ensure that all databases are always closed on exit #1187

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ func executeTestCase(
syncChans := []chan struct{}{}
nodeAddresses := []string{}
nodes := getStartingNodes(ctx, t, dbt, collectionNames, testCase)
// It is very important that the databases are always closed, otherwise resources will leak
// as tests run. This is particularly important for file based datastores.
defer closeNodes(ctx, t, &nodes)

// Documents and Collections may already exist in the database if actions have been split
// by the change detector so we should fetch them here at the start too (if they exist).
// collections are by node (index), as they are specific to nodes.
Expand Down Expand Up @@ -400,8 +404,15 @@ func executeTestCase(
assert.Fail(t, "timeout occurred while waiting for data stream", testCase.Description)
}
}
}

for _, node := range nodes {
// closeNodes closes all the given nodes, ensuring that resources are properly released.
func closeNodes(
ctx context.Context,
t *testing.T,
nodes *[]*node.Node,
) {
for _, node := range *nodes {
if node.Peer != nil {
err := node.Close()
require.NoError(t, err)
Expand Down