Skip to content

cache/upstream: Create an upstream cache package - #3

Merged
kalbasit merged 19 commits into
mainfrom
upstream-cache
Dec 1, 2024
Merged

kalbasit merged 19 commits into
mainfrom
upstream-cache

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

The upstream package will be used to pull narinfos and nars to the local cache.

* main:
  devbox: install golangci-lint at its latest version
  GitHub: Configure action to run golangci-lint
* main:
  GitHub: Disable build for multiple platforms
  golangci-lint: Enable many of the linters (#4)
* main:
  GitHub: Improve the CI test
* main:
  GitHub: Remove dead code
  GitHub: Use the same Go version as we have in Nix
* main:
  devbox: Prefer double quotes
* main:
  nixcacheinfo: Create a parser to parse NixCacheInfo (#5)
@kalbasit
kalbasit merged commit ec8cd99 into main Dec 1, 2024
@kalbasit
kalbasit deleted the upstream-cache branch December 1, 2024 04:52
kalbasit added a commit that referenced this pull request Dec 1, 2024
* main:
  cache/upstream: Create an upstream cache package (#3)
  nixcacheinfo: Create a parser to parse NixCacheInfo (#5)
  devbox: Prefer double quotes
  GitHub: Remove dead code
  GitHub: Use the same Go version as we have in Nix
  GitHub: Improve the CI test
  GitHub: Disable build for multiple platforms
  golangci-lint: Enable many of the linters (#4)
  devbox: install golangci-lint at its latest version
  GitHub: Configure action to run golangci-lint
kalbasit added a commit that referenced this pull request May 24, 2026
## Summary

Three pre-existing `pkg/cache` flakes from #1247 share one root cause:
assertions that race against absolute wall-clock time and break under CI
load even when the production code is correct. Surfaced repeatedly
during the lean-flake-check measurement runs in #1249 (which sits
stacked on top of this branch).

All three fixes are **test-only**. No production code is touched.

## What changed

| Flake (from #1247) | Test | Before | After |
| --- | --- | --- | --- |
| #5 |
`TestCDCBackends/{SQLite,MySQL}/first_pull_completes_before_CDC_chunking_finishes`
| `assert.Less(elapsed, 500ms)` racing the slow chunker | Happens-before
check: `select { case <-chunkingStarted: t.Fatal(…) }` after
`io.ReadAll`. `slowChunker` grew an optional `started chan struct{}`
closed when its delay expires. Delay bumped 500 ms → 10 s (only matters
under regression). |
| #1 | `TestCacheBackends/MySQL/PutNarInfoDeadlock` |
`context.WithTimeout(2s)` then `assert.NoError`. Could not distinguish
"deadlock" from "MariaDB slow." | Timeout bumped 2 s → 60 s. A real
deadlock still fails fast; non-deadlocked slow path now passes. |
| #2 | Six instances of `assert.WithinDuration(CreatedAt,
LastAccessedAt, 2s)` across `TestCacheBackends` | 2 s tolerance was
tight enough that two CLOSE-TO-NOW() timestamps from different SQL
operations under MariaDB load could fall outside it (observed -3 s
spread). | Tolerance bumped 2 s → 30 s. Still tight enough to catch a
genuinely broken "set both timestamps at row creation" semantic. |

## Why "test-only" and not "fix the production bug"

These three are *measurement bugs*: the assertions encode an assumption
("operation X completes within Y milliseconds") that's an artifact of
the dev host's speed, not a property the codebase ever promised. The
behavior the tests *want* to verify (no deadlock, timestamps set close
together at creation, GetNar doesn't block on chunking) is still being
verified — the encoding is just no longer wall-clock-dependent.

Flakes #3 and #4 from #1247 are NOT addressed here because they are not
the same shape:

- **#3** (`ConcurrentDownloadCancelOneClientOthersContinue`, 20-min
hang) is a real hang in `io.ReadAll(readerB)` or `wg.Wait()` after all
the existing 5–10 s guards have passed — almost certainly a
production-code bug in the shared-reader-fanout path. Filed as **#1252**
for separate investigation.
- **#4** (`GetNarInfoConcurrentPutNarInfoDuringMigration`) exercises the
same concurrent-migration-vs-PutNarInfo window that the next test
(`testGetNarInfoMultipleConcurrentPutsDuringMigration`) explicitly
`t.Skip`s with `"blocked on pgx transaction-abort cascade in PutNarInfo
re-fetch path"`. That tracked production bug is the actual root cause;
this test exercising it less reliably isn't a separate issue.

## Stack

This PR is stacked under #1249 (`improve-flake-check-time`); landing
this first should unblock #1249's CI by eliminating three of the five
flakes that were causing intermittent reds.

```
main → fix-cache-test-timing-assertions (this PR, #1253)
     → improve-flake-check-time (#1249)
```

## Test plan

- [x] `nix develop -- go test -race -count=1 -run
"TestCDCBackends/SQLite/first_pull_completes_before_CDC_chunking_finishes"
./pkg/cache/` passes locally.
- [x] `nix develop -- go test -race -count=1 -run
"TestCacheBackends/SQLite/(PutNarInfoDeadlock|GetNarInfo/narinfo_exists_upstream/nar_does_exist)"
./pkg/cache/` passes locally.
- [x] `golangci-lint run` clean (run inside `nix develop` so the
toolchain resolves).

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant