Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2022-01-24 18:45:53 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-01-27 15:51:08 +0300
commit6c91c8e8b0917567fdcd6b14b075c8bdf20d2c5f (patch)
tree38f87248a6ee7993e137aa74580c3860558511a0 /internal/bootstrap
parentb4a1fffaa707d5f0dc19af21f06947d0274db878 (diff)
Automatically clean up testhelper.Context
testhelper.Context() currently return a cancellation function as a second return value. Majority of the tests do not need to explicitly cancel the context but they simply defer its cancellation to clean up after the test. Given this, we can reduce the test verbosity and make testhelper.Context easier to compose by removing the unnecessary second return value. This adds a t.Cleanup function to automatically cancel the context at the end of the tests and omits the returned cancellation function. Tests which simply `defer cancel()` have had the extra call removed. Some tests explicitly call the cancellation, and these tests have been modified to add context.WithCancel around the testhelper.Context call. There are a few loctions where testing.TB was passed down to test helpers that create the context.
Diffstat (limited to 'internal/bootstrap')
-rw-r--r--internal/bootstrap/bootstrap_test.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go
index 0c1d818c2..9265e5194 100644
--- a/internal/bootstrap/bootstrap_test.go
+++ b/internal/bootstrap/bootstrap_test.go
@@ -88,8 +88,7 @@ func TestBootstrap_unixListener(t *testing.T) {
}
func TestBootstrap_listenerError(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx := testhelper.Context(t)
b, upgrader, listeners := setup(t, ctx)
@@ -109,8 +108,7 @@ func TestBootstrap_listenerError(t *testing.T) {
func TestBootstrap_signal(t *testing.T) {
for _, sig := range []syscall.Signal{syscall.SIGTERM, syscall.SIGINT} {
t.Run(sig.String(), func(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx := testhelper.Context(t)
b, upgrader, _ := setup(t, ctx)
@@ -133,8 +131,7 @@ func TestBootstrap_signal(t *testing.T) {
}
func TestBootstrap_gracefulTerminationStuck(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx, cancel := context.WithCancel(testhelper.Context(t))
b, upgrader, _ := setup(t, ctx)
@@ -159,8 +156,7 @@ func TestBootstrap_gracefulTerminationStuck(t *testing.T) {
func TestBootstrap_gracefulTerminationWithSignals(t *testing.T) {
for _, sig := range []syscall.Signal{syscall.SIGTERM, syscall.SIGINT} {
t.Run(sig.String(), func(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx, cancel := context.WithCancel(testhelper.Context(t))
b, upgrader, _ := setup(t, ctx)
@@ -184,8 +180,7 @@ func TestBootstrap_gracefulTerminationWithSignals(t *testing.T) {
}
func TestBootstrap_gracefulTerminationTimeoutWithListenerError(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx, cancel := context.WithCancel(testhelper.Context(t))
b, upgrader, listeners := setup(t, ctx)
@@ -212,8 +207,7 @@ func TestBootstrap_gracefulTerminationTimeoutWithListenerError(t *testing.T) {
}
func TestBootstrap_gracefulTermination(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
+ ctx := testhelper.Context(t)
b, upgrader, _ := setup(t, ctx)