Merge "ref/test: simplifying InitRandGenerator()"
diff --git a/lib/security/serialization/serialization_test.go b/lib/security/serialization/serialization_test.go
index 2de7519..420b4a1 100644
--- a/lib/security/serialization/serialization_test.go
+++ b/lib/security/serialization/serialization_test.go
@@ -83,7 +83,7 @@
 }
 
 func TestRoundTrip(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	signer := newSigner()
 	d, s := &bufferCloser{}, &bufferCloser{}
 
diff --git a/runtime/internal/lib/deque/deque_test.go b/runtime/internal/lib/deque/deque_test.go
index 9cac8e0..2595bf4 100644
--- a/runtime/internal/lib/deque/deque_test.go
+++ b/runtime/internal/lib/deque/deque_test.go
@@ -136,7 +136,7 @@
 }
 
 func TestRandom(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	var q T
 	var contents []int
 	for i := 0; i != 1000; i++ {
diff --git a/runtime/internal/lib/sync/wait_group_test.go b/runtime/internal/lib/sync/wait_group_test.go
index 859b323..30c43e6 100644
--- a/runtime/internal/lib/sync/wait_group_test.go
+++ b/runtime/internal/lib/sync/wait_group_test.go
@@ -15,7 +15,7 @@
 // TestRandom tests Wait after a random sequence of TryAdd's and Done's that
 // leaves the counter at 0.
 func TestRandom(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	var w WaitGroup
 	N := 100
 
diff --git a/runtime/internal/rpc/results_store_test.go b/runtime/internal/rpc/results_store_test.go
index b38b652..7578acf 100644
--- a/runtime/internal/rpc/results_store_test.go
+++ b/runtime/internal/rpc/results_store_test.go
@@ -29,7 +29,7 @@
 func (p keySlice) Sort()              { sort.Sort(p) }
 
 func TestStoreRandom(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	store := newStore()
 	keys := randomKeys()
 
@@ -51,7 +51,7 @@
 }
 
 func TestStoreOrdered(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	store := newStore()
 	keys := randomKeys()
 
@@ -96,7 +96,7 @@
 }
 
 func TestStoreWaitForEntryRandom(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	store := newStore()
 	keys := randomKeys()
 	var wg sync.WaitGroup
@@ -118,7 +118,7 @@
 }
 
 func TestStoreWaitForRemovedEntry(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	store := newStore()
 	keys := randomKeys()
 	var wg sync.WaitGroup
diff --git a/runtime/internal/rpc/stream/vc/vc_test.go b/runtime/internal/rpc/stream/vc/vc_test.go
index 6e2737f..7246383 100644
--- a/runtime/internal/rpc/stream/vc/vc_test.go
+++ b/runtime/internal/rpc/stream/vc/vc_test.go
@@ -62,7 +62,7 @@
 // testFlowEcho writes a random string of 'size' bytes on the flow and then
 // ensures that the same string is read back.
 func testFlowEcho(t *testing.T, flow stream.Flow, size int) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	defer flow.Close()
 	wrote := testutil.RandomBytes(size)
 	go func() {
diff --git a/runtime/internal/rpc/stream/vif/vif_test.go b/runtime/internal/rpc/stream/vif/vif_test.go
index 9d53964..b73ed57 100644
--- a/runtime/internal/rpc/stream/vif/vif_test.go
+++ b/runtime/internal/rpc/stream/vif/vif_test.go
@@ -85,7 +85,7 @@
 }
 
 func testMultipleVCsAndMultipleFlows(t *testing.T, gomaxprocs int) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	// This test dials multiple VCs from the client to the server.
 	// On each VC, it creates multiple flows, writes to them and verifies
 	// that the other process received what was written.
diff --git a/runtime/internal/testing/concurrency/clock_test.go b/runtime/internal/testing/concurrency/clock_test.go
index dcbd6fc..12b22c5 100644
--- a/runtime/internal/testing/concurrency/clock_test.go
+++ b/runtime/internal/testing/concurrency/clock_test.go
@@ -14,7 +14,7 @@
 
 // TestClone checks the clone() method of a clock.
 func TestClone(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	c1 := newClock()
 	c1[0] = testutil.RandomIntn(100)
 	c2 := c1.clone()
diff --git a/services/binary/binaryd/binaryd_v23_test.go b/services/binary/binaryd/binaryd_v23_test.go
index 0a3c05a..cdd6faf 100644
--- a/services/binary/binaryd/binaryd_v23_test.go
+++ b/services/binary/binaryd/binaryd_v23_test.go
@@ -96,7 +96,7 @@
 }
 
 func V23TestBinaryRepositoryIntegration(i *v23tests.T) {
-	defer testutil.InitRandGenerator(i.Logf)()
+	testutil.InitRandGenerator(i.Logf)
 	v23tests.RunRootMT(i, "--v23.tcp.address=127.0.0.1:0")
 
 	// Build the required binaries.
diff --git a/services/device/deviced/internal/impl/globsuid/signature_match_test.go b/services/device/deviced/internal/impl/globsuid/signature_match_test.go
index e1e8827..8f7c3c5 100644
--- a/services/device/deviced/internal/impl/globsuid/signature_match_test.go
+++ b/services/device/deviced/internal/impl/globsuid/signature_match_test.go
@@ -28,7 +28,7 @@
 )
 
 func TestDownloadSignatureMatch(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
diff --git a/services/internal/binarylib/client_test.go b/services/internal/binarylib/client_test.go
index 460f44a..000e8ca 100644
--- a/services/internal/binarylib/client_test.go
+++ b/services/internal/binarylib/client_test.go
@@ -73,7 +73,7 @@
 // TestBufferAPI tests the binary repository client-side library
 // interface using buffers.
 func TestBufferAPI(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
@@ -125,7 +125,7 @@
 // TestFileAPI tests the binary repository client-side library
 // interface using files.
 func TestFileAPI(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
diff --git a/services/internal/binarylib/http_test.go b/services/internal/binarylib/http_test.go
index a01a4f6..73b253f 100644
--- a/services/internal/binarylib/http_test.go
+++ b/services/internal/binarylib/http_test.go
@@ -21,7 +21,7 @@
 
 // TestHTTP checks that HTTP download works.
 func TestHTTP(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
diff --git a/services/internal/binarylib/impl_test.go b/services/internal/binarylib/impl_test.go
index 054f5ca..a614217 100644
--- a/services/internal/binarylib/impl_test.go
+++ b/services/internal/binarylib/impl_test.go
@@ -181,7 +181,7 @@
 // resumption ranging the number of parts the uploaded binary consists
 // of.
 func TestResumption(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
@@ -227,7 +227,7 @@
 
 // TestErrors checks that the binary interface correctly reports errors.
 func TestErrors(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
diff --git a/test/modules/queue_rw_test.go b/test/modules/queue_rw_test.go
index fd55475..af20b44 100644
--- a/test/modules/queue_rw_test.go
+++ b/test/modules/queue_rw_test.go
@@ -14,7 +14,7 @@
 )
 
 func TestQueueRW(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	q := modules.NewRW()
 	size := testutil.RandomIntn(1000)
 	data := testutil.RandomBytes(size)
diff --git a/test/testutil/rand.go b/test/testutil/rand.go
index dd65af1..3cb1526 100644
--- a/test/testutil/rand.go
+++ b/test/testutil/rand.go
@@ -92,15 +92,11 @@
 // and returns a function intended to be defer'ed that prints out the
 // seed use when creating the number number generator using the supplied
 // logging function.
-func InitRandGenerator(loggingFunc func(format string, args ...interface{})) func() {
+func InitRandGenerator(loggingFunc func(format string, args ...interface{})) {
 	once.Do(func() {
 		Rand = NewRandGenerator()
+		loggingFunc("Seeded pseudo-random number generator with %v", Rand.seed)
 	})
-	return func() {
-		if loggingFunc != nil {
-			loggingFunc("Seeded pseudo-random number generator with %v", Rand.seed)
-		}
-	}
 }
 
 var (
diff --git a/test/testutil/testdata/rand_test.go b/test/testutil/testdata/rand_test.go
index bddb946..7e403b7 100644
--- a/test/testutil/testdata/rand_test.go
+++ b/test/testutil/testdata/rand_test.go
@@ -11,7 +11,7 @@
 )
 
 func TestRandSeed(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	t.Logf("rand: %d", testutil.RandomInt())
 	t.FailNow()
 }
diff --git a/test/testutil/util_test.go b/test/testutil/util_test.go
index b2ed9f5..56f1ebc 100644
--- a/test/testutil/util_test.go
+++ b/test/testutil/util_test.go
@@ -45,21 +45,21 @@
 	v23bin := i.BinaryFromPath("v23")
 	inv := v23bin.Start("go", "test", "./testdata")
 	inv.ExpectRE("FAIL: TestRandSeed.*", 1)
-	parts := inv.ExpectRE(`rand: (\d+)`, -1)
+	parts := inv.ExpectRE(`Seeded pseudo-random number generator with (\d+)`, -1)
+	if len(parts) != 1 || len(parts[0]) != 2 {
+		i.Fatalf("failed to match regexp")
+	}
+	seed := parts[0][1]
+	parts = inv.ExpectRE(`rand: (\d+)`, -1)
 	if len(parts) != 1 || len(parts[0]) != 2 {
 		i.Fatalf("failed to match regexp")
 	}
 	randInt := parts[0][1]
-	parts = inv.ExpectRE(`Seeded pseudo-random number generator with (\d+)`, -1)
-	if len(parts) != 1 || len(parts[0]) != 2 {
-		i.Fatalf("failed to match regexp")
-	}
 
-	seed := parts[0][1]
 	// Rerun the test, this time with the seed that we want to use.
 	v23bin = v23bin.WithEnv("V23_RNG_SEED=" + seed)
 	inv = v23bin.Start("go", "test", "./testdata")
 	inv.ExpectRE("FAIL: TestRandSeed.*", 1)
-	inv.ExpectRE("rand: "+randInt, 1)
 	inv.ExpectRE("Seeded pseudo-random number generator with "+seed, -1)
+	inv.ExpectRE("rand: "+randInt, 1)
 }
diff --git a/test/v23tests/v23tests_test.go b/test/v23tests/v23tests_test.go
index 137cf47..5271ce1 100644
--- a/test/v23tests/v23tests_test.go
+++ b/test/v23tests/v23tests_test.go
@@ -144,7 +144,7 @@
 }
 
 func TestInputRedirection(t *testing.T) {
-	defer testutil.InitRandGenerator(t.Logf)()
+	testutil.InitRandGenerator(t.Logf)
 	env := v23tests.New(t)
 	defer env.Cleanup()