moby/distribution/xfer
Kir Kolyshkin 33c205be4f
TestTransfer*: don't call t.Fatal from a goroutine
staticcheck go linter warns:

> distribution/xfer/transfer_test.go:37:2: SA2002: the goroutine calls T.Fatalf, which must be called in the same goroutine as the test (staticcheck)

What it doesn't say is why. The reason is, t.Fatalf() calls t.FailNow(),
which is expected to stop test execution right now. It does so by
calling runtime.Goexit(), which, unless called from a main goroutine,
does not stop test execution.

Anyway, long story short, if we don't care much about stopping the test
case immediately, we can just replace t.Fatalf() with t.Errorf() which
still marks the test case as failed, but won't stop it immediately.

This patch was tested to check that the test fails if any of the
goroutines call t.Errorf():

1. Failure in DoFunc ("transfer function not started ...") was tested by
decreading the NewTransferManager() argument:

-        tm := NewTransferManager(5)
+        tm := NewTransferManager(2)

2. Failure "got unexpected progress value" was tested by injecting a random:

-                       if present && p.Current <= val {
+                       if present && p.Current <= val || rand.Intn(100) > 80 {

3. Failure in DoFunc ("too many jobs running") was tested by increasing
the NewTransferManager() argument:

-       tm := NewTransferManager(concurrencyLimit)
+       tm := NewTransferManager(concurrencyLimit + 1)

While at it:
 * fix/amend some error messages
 * use _ for unused arguments of DoFunc

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-09-18 12:57:37 +02:00
..
download.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
download_test.go goimports: fix imports 2019-09-18 12:56:54 +02:00
transfer.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
transfer_test.go TestTransfer*: don't call t.Fatal from a goroutine 2019-09-18 12:57:37 +02:00
upload.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
upload_test.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00