aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/version_map_test.go
AgeCommit message (Collapse)Author
2023-08-23all: remove arbitrary hard-coded timeouts in testsBryan C. Mills
If a test times out, that implies that it got stuck on something. By default, the Go testing package dumps goroutines when its own timeout is passed, which prints a goroutine dump, helping to reveal what was stuck. Adding an arbitrary timeout on top of the testing package's own timeout is, in my experience, almost always counterproductive. If the arbitrary timeout catches a real hang, it causes the test to fail instead of dumping goroutines, making it much harder to see what was stuck. On the other hand, if the timeouts are set aggressively enough to make the test fail early, they are often too aggressive for CI testing, causing flakes that then have to be triaged on an ongoing basis. On balance, the value of saving a minute or two for developers who have introduced a hang is not worth the cost of suppressing debugging information and causing flakes that have to be triaged. Fixes #61556. For #59347. Change-Id: I0263d0d9b18283470f100e5a0155818b87b5312f Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/521837 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
2021-06-07internal/version: drop Version suffix from constantsJulie Qiu
To avoid repetition, the "Version" suffix in version.LatestVersion, version.MainVersion, and version.MasterVersion are dropped. The current version.Latest function is renamed to version.LatestVersion. Change-Id: I649229939223b686dd95a137df4871a899f48aab Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/325390 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
2021-06-07internal: move version constants to internal/versionJulie Qiu
Because the constants for "latest", "master" and "main" were in package internal, we couldn't use them in internal/stdlib due to an import cycle. They are now moved to internal/version to avoid this cycle. Change-Id: I6ebe7c0f50037be2b047c4a25054a0531dcfd3f8 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/325389 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
2021-04-08internal/postgres,etc: finish MustInsertModule cleanupJonathan Amsterdam
Now that there are no callers of MustInsertModule, rename MustInsertModuleLatest to MustInsertModule. We can also remove MustInsertModuleLMV. Change-Id: Ieb554ee32696c168be4cc0a14ecece9f4c6b91b4 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/308271 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
2021-04-07internal/postgres: use MustInsertModuleLatestJonathan Amsterdam
For most internal/postgres tests, update latest-version information when we insert a module. That is more like what actually happens on the worker, and some features now rely on it, so we should do it everywhere. Some tests still use a custom go.mod file, so we can't switch to MustInsertModuleLatest for those, because it uses a minimal go.mod file. Change-Id: Ie5030aee4ed9c837931fddb8757e37bf6373a8c7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/307871 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com>
2021-02-12internal/postgres: parallelize testsJonathan Amsterdam
Run tests in parallel on separate databases. With four DBs, the time to run all the package's tests is cut in about half, from 50s to 25s (the time varies from run to run). Instead of a global variable holding a single DB, we set up a channel populated with DBs. Each test receives from the channel to get a DB to use, and sends it to the channel when done. Because a test may have to wait to get a DB, we can't set an individual timeout for some tests because acquiring the DB can take some time. Individual test timeouts aren't really important, because `go test` will time out the entire run after 10 minutes anyway. The only test that can't be run in parallel is TestSearch, because it reads metrics before and after each sub-test to compute a delta, thereby implicitly assuming that no other Search calls are running in parallel. Change-Id: Icb35dbd2f146e27d82d4eef81343cf9725252155 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/291449 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
2021-02-11internal/postgres: add MustInsertModule for testingJonathan Amsterdam
Simplifies frequent calls to InsertModule. Change-Id: Iafcf5ec8d71eb9ab541ceecb2d85eb0d9b5119b1 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/291269 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
2021-01-20internal: handle 290s on 404Julie Qiu
When a path 404s but the top level module exists, return the relevant response text. Also update the response text for clarity. Change-Id: I9425355daf4ad3f88c58261cc6f778f79f0fc003 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/284585 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2021-01-06internal/postgres: add GetVersionMapsNon2xxStatusJulie Qiu
GetVersionMapsWithNon2xxStatus is added, which returns the version_maps correlating to a given path with a 4xx or 5xx status. Change-Id: I99d52bbc38183939331e2d991a3107635036ea5b Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/281673 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-10-26internal/testing/sample: rename LegacyModule to ModuleJulie Qiu
For golang/go#39629 Change-Id: I83c2afdf32b58594e9ab00b545ae1bfebbd5491b Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/265005 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-10-01internal/testing/sample: prefix legacy functions with LegacyJulie Qiu
For golang/go#39629 Change-Id: I3953c39e419ac8b74ac7f61ac6ffa9ec39e288aa Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258599 Trust: Julie Qiu <julie@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-27internal/postgres: fetch version_map.updated_atJulie Qiu
GetVersionMap now returns the UpdatedAt timestamp for a given row. Since it is possible for a module to 404, but appear in the index at a later time, this information will be used to determine whether we should refetch a given module. For golang/go#37002 Change-Id: If6a9e3a5d3580d58f8aafd9b40495b1fa0551e91 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/244600 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-07internal: delete insert-directories experimentJulie Qiu
The insert-directories experiment flag is deleted, since we have already inserted data for all modules into the paths, package_imports, documentation, and readmes table, and been running that code path for a while. Updates golang/go#39629 Change-Id: I323850a462672c41ad0c67b6ab2b173bb32bf441 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/241320 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-07-06internal/experiment: improve ergonomics for NewSet and NewContextJulie Qiu
Previously, NewSet and NewContext required the caller to construct a set that was passed in. The functions now accept experiment names, to make them easier to use. Change-Id: Id306902910d51483c48a6a3bc8205cf484694d6a Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/240857 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-06-16internal: avoid "if err = f(); err != nil" patternDaniel Martí
Use shadowing via ":=", which clearly signals we're not storing the error value in a variable to be used at a later time. This way, one knows that the error value is scoped to the if statement, so there is less to keep in one's head. Change-Id: Ibfb5efc92e9500a525ca58ad341d59ced0581fd9 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/238043 Reviewed-by: Julie Qiu <julie@golang.org>
2020-05-13internal/postgres: change GetVersionMap logicJulie Qiu
The logic for GetVersionMap is changed so that an explicit module path is now required. All logic is also now the same for all requestedVersions (as opposed to a special case for latest). This function is only used by the frontend to check if a version exists as part of a frontend fetch, and this behavior makes more sense for that use case. Updates golang/go#36811 Updates golang/go#37002 Updates golang/go#37106 Change-Id: I415a2730daa6edc023f80c0c615521047311f35b Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/744833 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-05-04many: use the new sample APIJonathan Amsterdam
Replace many calls to sample.DefaultModule, and all calls to sample.DefaultPackage, with calls to the new Module and Package functions. Change-Id: I76921e14502585f8ca9a4dba5de01d7055522f3f Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/733604 Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-05-01internal/testing/sample: improvementsJonathan Amsterdam
This is the first step towards making sample clearer and less error-prone. - Rename Module and Package to DefaultModule and DefaultPackage, so existing code continues to work. In later CLs, I'll replace most or all calls to these functions. - Define ModuleInfo, Module and Package to take as arguments the most common fields. The Module function does _not_ create a package; it returns a module with no packages. - Most important: define AddPackage, which adds a Package to a Module and correctly updates Module.Directories. - Remove VersionedPackage, since it's clearer to create one directly. - Update a couple of call sites, just to get tests to pass. More updates in a later CL. Change-Id: I46eb94ba897d4f122483b58435107b8782c6044f Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/733619 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-04-23all: rename module to golang.org/x/pkgsiteJulie Qiu
golang.org/x/discovery is renamed to golang.org/x/pkgsite. When the repository is open sourced, it will be hosted at go.googlesource.com/pkgsite. Change-Id: Ifc3b45b771a385b99179e785447f2a87afcacf87 Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/724273 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-04-06all: rename internal.Version to internal.ModuleJonathan Amsterdam
Rename the type, and any variable of that type. Rename most functions from *Version* to *Module*, where it made sense. No other changes. Updates b/150143758. Change-Id: I13079411376be0af7e53a577fc6ca1c92c38b6cd Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/677160 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Julie Qiu <julieqiu@google.com>
2020-03-27internal/postgres: read/write from version_mapJulie Qiu
Updates b/135954292 Change-Id: I358e2265f5114056f8b5da75f0b261a8bf29f56d Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/649158 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>