aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/unit_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-03-12 15:18:32 -0500
committerJonathan Amsterdam <jba@google.com>2021-03-16 18:33:03 +0000
commit38233971b438ea5c22111c50740f996e34f89dfb (patch)
tree13bc9f1ab17f5448e7efaba0305b817ca5332b75 /internal/postgres/unit_test.go
parent5a3c43e7e8b7a084d4a72d369c8f71e7c1a9e61d (diff)
downloadgo-x-pkgsite-38233971b438ea5c22111c50740f996e34f89dfb.tar.xz
internal/worker,etc.: improvements to latest-version info
- Fetch and update the latest-version info before processing a module rather than after, so the information in the DB matches what InsertModule is using. - Pass latest-version info to InsertModule so it can use it to decide whether the version being inserted is the latest version. - InsertModule writes the good latest version to the latest_module_versions table while holding the advisory lock, avoiding a race condition where two different versions both think they're the latest. For golang/go#44710 Change-Id: Id5e8fa7a384ec6d4d86257362fd33a8fcd5215f7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/301929 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/unit_test.go')
-rw-r--r--internal/postgres/unit_test.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index 5a80254f..df031284 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -649,14 +649,15 @@ func TestGetLatestUnitVersion(t *testing.T) {
testDB, release := acquire(t)
defer release()
+ lmvs := map[string]*internal.LatestModuleVersions{}
+ for _, l := range test.latests {
+ modFile := fmt.Sprintf("module %s\n%s", l.module, l.goMod)
+ lmvs[l.module] = addLatest(ctx, t, testDB, l.module, l.version, modFile)
+ }
for _, p := range test.packages {
mod, ver, pkg := parseModuleVersionPackage(p)
m := sample.Module(mod, ver, pkg)
- MustInsertModule(ctx, t, testDB, m)
- }
- for _, l := range test.latests {
- modFile := fmt.Sprintf("module %s\n%s", l.module, l.goMod)
- addLatest(ctx, t, testDB, l.module, l.version, modFile)
+ MustInsertModuleLMV(ctx, t, testDB, m, lmvs[mod])
}
if test.modulePath == "" {
test.modulePath = internal.UnknownModulePath