-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for Go 1.24 test contexts
Signed-off-by: AbstractionFactory <[email protected]>
- Loading branch information
1 parent
63248f3
commit 2e11b56
Showing
4 changed files
with
44 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,26 +1,19 @@ | ||
// Copyright (c) The OpenTofu Authors | ||
// SPDX-License-Identifier: MPL-2.0 | ||
// Copyright (c) 2023 HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tofutestutils | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/opentofu/tofutestutils/testcontext" | ||
"testing" | ||
) | ||
|
||
const minCleanupSafety = time.Second * 30 | ||
const maxCleanupSafety = time.Minute * 5 | ||
|
||
// Context returns a context configured for the test deadline. This function configures a context with 25% safety for | ||
// any cleanup tasks to finish. For a more flexible function see testcontext.Context. | ||
// Context creates a context with a deadline that allows for enough time to clean up a test before the testing framework | ||
// unceremoniously kills the process. Starting with Go 1.24, this function is an alias for t.Context(). In Go 1.23 and | ||
// lower this function reserves 25% of the test timeout, minimum 1 minute, maximum 5 minutes for cleanup. | ||
func Context(t *testing.T) context.Context { | ||
return testcontext.Context( | ||
t, | ||
4, | ||
minCleanupSafety, | ||
maxCleanupSafety, | ||
) | ||
return testcontext.Context(t) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) The OpenTofu Authors | ||
// SPDX-License-Identifier: MPL-2.0 | ||
// Copyright (c) 2023 HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//go:build go1.24 | ||
|
||
package testcontext | ||
|
||
// Context creates a context with a deadline that allows for enough time to clean up a test before the testing framework | ||
// unceremoniously kills the process. Starting with Go 1.24, this function is an alias for t.Context(). In Go 1.23 and | ||
// lower this function reserves 25% of the test timeout, minimum 1 minute, maximum 5 minutes for cleanup. | ||
func Context(t *testing.T) context.Context { | ||
return t.Context() | ||
} |
This file contains 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 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