Run of fresh-snapshots for golang-github-fortytw2-leaktest

Merge these changes:

Summary

Merged new upstream version: 1.3.0+git20190606.1.d73c753 (was: 1.3.0).

Diff

Branch: main

diff --git a/README.md b/README.md
index 82822bf..b085312 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,8 @@ func TestPoolTimeout(t *testing.T) {
 
 // Use Go 1.7+ context.Context for cancellation
 func TestPoolContext(t *testing.T) {
-    ctx, _ := context.WithTimeout(context.Background(), time.Second)
+    ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+    defer cancel()
     defer leaktest.CheckContext(ctx, t)()
 
     go func() {
diff --git a/debian/changelog b/debian/changelog
index 7becfb9..215964f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-golang-github-fortytw2-leaktest (1.3.0-2) UNRELEASED; urgency=low
+golang-github-fortytw2-leaktest (1.3.0+git20190606.1.d73c753-1) UNRELEASED; urgency=low
 
   * Bump debhelper from old 11 to 12.
   * Set debhelper-compat version in Build-Depends.
@@ -6,8 +6,9 @@ golang-github-fortytw2-leaktest (1.3.0-2) UNRELEASED; urgency=low
     Repository-Browse.
   * Apply multi-arch hints.
     + golang-github-fortytw2-leaktest-dev: Add Multi-Arch: foreign.
+  * New upstream snapshot.
 
- -- Debian Janitor <janitor@jelmer.uk>  Sat, 06 Jun 2020 14:15:15 -0000
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 28 Mar 2022 04:11:10 -0000
 
 golang-github-fortytw2-leaktest (1.3.0-1) unstable; urgency=medium
 
diff --git a/leaktest.go b/leaktest.go
index 219e930..ef59936 100644
--- a/leaktest.go
+++ b/leaktest.go
@@ -19,6 +19,9 @@ import (
 	"time"
 )
 
+// TickerInterval defines the interval used by the ticker in Check* functions.
+var TickerInterval = time.Millisecond * 50
+
 type goroutine struct {
 	id    uint64
 	stack string
@@ -91,6 +94,20 @@ func interestingGoroutines(t ErrorReporter) []*goroutine {
 	return gs
 }
 
+// leakedGoroutines returns all goroutines we are considering leaked and
+// the boolean flag indicating if no leaks detected
+func leakedGoroutines(orig map[uint64]bool, interesting []*goroutine) ([]string, bool) {
+	leaked := make([]string, 0)
+	flag := true
+	for _, g := range interesting {
+		if !orig[g.id] {
+			leaked = append(leaked, g.stack)
+			flag = false
+		}
+	}
+	return leaked, flag
+}
+
 // ErrorReporter is a tiny subset of a testing.TB to make testing not such a
 // massive pain
 type ErrorReporter interface {
@@ -126,26 +143,27 @@ func CheckContext(ctx context.Context, t ErrorReporter) func() {
 	}
 	return func() {
 		var leaked []string
+		var ok bool
+		// fast check if we have no leaks
+		if leaked, ok = leakedGoroutines(orig, interestingGoroutines(t)); ok {
+			return
+		}
+		ticker := time.NewTicker(TickerInterval)
+		defer ticker.Stop()
+
 		for {
 			select {
-			case <-ctx.Done():
-				t.Errorf("leaktest: timed out checking goroutines")
-			default:
-				leaked = make([]string, 0)
-				for _, g := range interestingGoroutines(t) {
-					if !orig[g.id] {
-						leaked = append(leaked, g.stack)
-					}
-				}
-				if len(leaked) == 0 {
+			case <-ticker.C:
+				if leaked, ok = leakedGoroutines(orig, interestingGoroutines(t)); ok {
 					return
 				}
-				// don't spin needlessly
-				time.Sleep(time.Millisecond * 50)
 				continue
+			case <-ctx.Done():
+				t.Errorf("leaktest: %v", ctx.Err())
 			}
 			break
 		}
+
 		for _, g := range leaked {
 			t.Errorf("leaktest: leaked goroutine: %v", g)
 		}

Branch: pristine-tar

diff --git a/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.delta b/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.delta
new file mode 100644
index 0000000..b864cac
Binary files /dev/null and b/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.delta differ
diff --git a/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.id b/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.id
new file mode 100644
index 0000000..6c5539d
--- /dev/null
+++ b/golang-github-fortytw2-leaktest_1.3.0+git20190606.1.d73c753.orig.tar.gz.id
@@ -0,0 +1 @@
+51d131ef90f899f18a4adc585b4a85ef23ef9b57

Branch: upstream

Tag: upstream/1.3.0+git20190606.1.d73c753
diff --git a/README.md b/README.md
index 82822bf..b085312 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,8 @@ func TestPoolTimeout(t *testing.T) {
 
 // Use Go 1.7+ context.Context for cancellation
 func TestPoolContext(t *testing.T) {
-    ctx, _ := context.WithTimeout(context.Background(), time.Second)
+    ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+    defer cancel()
     defer leaktest.CheckContext(ctx, t)()
 
     go func() {
diff --git a/leaktest.go b/leaktest.go
index 219e930..ef59936 100644
--- a/leaktest.go
+++ b/leaktest.go
@@ -19,6 +19,9 @@ import (
 	"time"
 )
 
+// TickerInterval defines the interval used by the ticker in Check* functions.
+var TickerInterval = time.Millisecond * 50
+
 type goroutine struct {
 	id    uint64
 	stack string
@@ -91,6 +94,20 @@ func interestingGoroutines(t ErrorReporter) []*goroutine {
 	return gs
 }
 
+// leakedGoroutines returns all goroutines we are considering leaked and
+// the boolean flag indicating if no leaks detected
+func leakedGoroutines(orig map[uint64]bool, interesting []*goroutine) ([]string, bool) {
+	leaked := make([]string, 0)
+	flag := true
+	for _, g := range interesting {
+		if !orig[g.id] {
+			leaked = append(leaked, g.stack)
+			flag = false
+		}
+	}
+	return leaked, flag
+}
+
 // ErrorReporter is a tiny subset of a testing.TB to make testing not such a
 // massive pain
 type ErrorReporter interface {
@@ -126,26 +143,27 @@ func CheckContext(ctx context.Context, t ErrorReporter) func() {
 	}
 	return func() {
 		var leaked []string
+		var ok bool
+		// fast check if we have no leaks
+		if leaked, ok = leakedGoroutines(orig, interestingGoroutines(t)); ok {
+			return
+		}
+		ticker := time.NewTicker(TickerInterval)
+		defer ticker.Stop()
+
 		for {
 			select {
-			case <-ctx.Done():
-				t.Errorf("leaktest: timed out checking goroutines")
-			default:
-				leaked = make([]string, 0)
-				for _, g := range interestingGoroutines(t) {
-					if !orig[g.id] {
-						leaked = append(leaked, g.stack)
-					}
-				}
-				if len(leaked) == 0 {
+			case <-ticker.C:
+				if leaked, ok = leakedGoroutines(orig, interestingGoroutines(t)); ok {
 					return
 				}
-				// don't spin needlessly
-				time.Sleep(time.Millisecond * 50)
 				continue
+			case <-ctx.Done():
+				t.Errorf("leaktest: %v", ctx.Err())
 			}
 			break
 		}
+
 		for _, g := range leaked {
 			t.Errorf("leaktest: leaked goroutine: %v", g)
 		}

Publish Blockers

  • ☑ run was successful
  • ☑ package has not been removed from the archive
  • ☑ command has not changed
  • ☒ not yet reviewed, but review needed
  • ☑ 0 publish attempts so far.not currently attempting to back off
  • ☒ merge proposals for the package maintainer are currently being rate-limited (open: 1257, max open: 300)
  • ☑ change set 58fdb878-90c2-4b75-b3e7-9068fcd0da4c is ready

Resulting package

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-snapshots golang-github-fortytw2-leaktest-dev

Lintian Result

Full worker log Full build log