diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-02-19 08:41:12 -0500 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-02-19 21:45:42 +0000 |
| commit | 98ffe01caf418206168dc9f9eb34733315dce3e6 (patch) | |
| tree | e8a17030b3bea4702567314e7b2b09cb1db0f553 /internal/postgres/unit_test.go | |
| parent | 8680fdf5411ee5f6dc4f785304b97301e3e70388 (diff) | |
| download | go-x-pkgsite-98ffe01caf418206168dc9f9eb34733315dce3e6.tar.xz | |
internal/testing/sample: make a fresh copy of Imports
Create a new slice of imports each time it's used.
This ensures that memory isn't shared between sample modules. It
addresses a race condition we saw when running postgres tests
concurrently.
Change-Id: I0c1e0112ff7b944433565c7cacdd7226a32ad4eb
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/294149
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/postgres/unit_test.go')
| -rw-r--r-- | internal/postgres/unit_test.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go index d9fad8b1..98d0d0dd 100644 --- a/internal/postgres/unit_test.go +++ b/internal/postgres/unit_test.go @@ -649,7 +649,7 @@ func TestGetUnitFieldSet(t *testing.T) { if fields&internal.WithMain != 0 { u.Documentation = []*internal.Documentation{sample.Doc} u.Readme = readme - u.NumImports = len(sample.Imports) + u.NumImports = len(sample.Imports()) u.Subdirectories = []*internal.PackageMeta{ { Path: "a.com/m/dir/p", @@ -661,8 +661,9 @@ func TestGetUnitFieldSet(t *testing.T) { } } if fields&internal.WithImports != 0 { - u.Imports = sample.Imports - u.NumImports = len(sample.Imports) + imps := sample.Imports() + u.Imports = imps + u.NumImports = len(imps) } if fields&internal.WithLicenses == 0 { u.LicenseContents = nil @@ -733,8 +734,9 @@ func unit(fullPath, modulePath, version, name string, readme *internal.Readme, s u.Subdirectories = subdirectories(modulePath, suffixes) if u.IsPackage() { - u.Imports = sample.Imports - u.NumImports = len(sample.Imports) + imps := sample.Imports() + u.Imports = imps + u.NumImports = len(imps) u.Documentation = []*internal.Documentation{sample.Doc} } return u |
