1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/distribution
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
..
fixtures/validate_manifest
metadata goimports: fix imports 2019-09-18 12:56:54 +02:00
utils Add canonical import comment 2018-02-05 16:51:57 -05:00
xfer TestTransfer*: don't call t.Fatal from a goroutine 2019-09-18 12:57:37 +02:00
config.go goimports: fix imports 2019-09-18 12:56:54 +02:00
errors.go goimports: fix imports 2019-09-18 12:56:54 +02:00
errors_test.go goimports: fix imports 2019-09-18 12:56:54 +02:00
oci.go Update containerd client to 1.2.4 2019-02-14 04:47:27 +01:00
pull.go goimports: fix imports 2019-09-18 12:56:54 +02:00
pull_v2.go Use io.SeekStart instead of os.SEEK_SET 2019-09-18 12:57:31 +02:00
pull_v2_test.go Remove unused functions, variables, fields 2019-09-18 12:57:12 +02:00
pull_v2_unix.go Improve 'no matching manifest' error 2019-01-15 18:24:15 +01:00
pull_v2_windows.go Use io.SeekStart instead of os.SEEK_SET 2019-09-18 12:57:31 +02:00
push.go Remove v1 manifest code 2019-06-18 01:40:25 +00:00
push_v2.go goimports: fix imports 2019-09-18 12:56:54 +02:00
push_v2_test.go goimports: fix imports 2019-09-18 12:56:54 +02:00
registry.go distribution: modify warning logic when pulling v2 schema1 manifests 2019-09-12 18:52:49 +00:00
registry_unit_test.go distribution: fix passing platform struct to puller 2018-06-27 14:59:31 -07:00