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/testing/sample/sample.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/testing/sample/sample.go')
| -rw-r--r-- | internal/testing/sample/sample.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go index 0418be09..d4ffff0e 100644 --- a/internal/testing/sample/sample.go +++ b/internal/testing/sample/sample.go @@ -47,7 +47,6 @@ var ( Suffix = "foo" PackagePath = path.Join(ModulePath, Suffix) V1Path = PackagePath - Imports = []string{"path/to/bar", "fmt"} ReadmeFilePath = "README.md" ReadmeContents = "readme" GOOS = internal.All @@ -203,12 +202,13 @@ func UnitForModuleRoot(m *internal.ModuleInfo) *internal.Unit { func UnitForPackage(path, modulePath, version, name string, isRedistributable bool) *internal.Unit { // Copy Doc because some tests modify it. doc := *Doc + imps := Imports() return &internal.Unit{ UnitMeta: *UnitMeta(path, modulePath, version, name, isRedistributable), Documentation: []*internal.Documentation{&doc}, LicenseContents: Licenses(), - Imports: Imports, - NumImports: len(Imports), + Imports: imps, + NumImports: len(imps), } } @@ -380,3 +380,7 @@ func Licenses() []*licenses.License { {Metadata: LicenseMetadata()[0], Contents: []byte(`Lorem Ipsum`)}, } } + +func Imports() []string { + return []string{"fmt", "path/to/bar"} +} |
