# Reproduce nats-io/nats-server's flaky tests in your own f+ DST account

f+ DST ran 9 of nats-io/nats-server's tests in its deterministic simulator; the results are at
https://staging.extrafunctional-staging.fyi/dst/nats-io/nats-server. This page is for your coding agent: it gives the tests, the commits and how to build the
image, so you can make them fail in your own account, replay them and check your fixes.

Do this, in a checkout of nats-io/nats-server:

1. Install and sign in: step 1 of https://staging.extrafunctional-staging.fyi/dst.md.
2. Pick tests from the list below instead of scanning (or scan too: step 2 of /dst.md finds newer flakes).
3. Build the image at the test's commit (recipe below), push it, check, then hunt: steps 3 and 4 of /dst.md.
4. Compare your finding's error with CI's error below, then follow /dst.md from step 5.

## The image

Go. One test binary for each package, built in the image (`go test -c` takes an import path from the module root):

    # .fplus/environment/Dockerfile
    FROM golang:<the go.mod version>-bookworm
    WORKDIR /src
    COPY . .
    RUN go test -c -race -o /src/t0.test github.com/nats-io/nats-server/v2/server && go list -f '{{.Dir}}' github.com/nats-io/nats-server/v2/server > /src/t0.dir
    RUN go test -c -race -o /src/t1.test github.com/nats-io/nats-server/v2/test && go list -f '{{.Dir}}' github.com/nats-io/nats-server/v2/test > /src/t1.dir

    # .fplus/environment/verify.sh TEST (TEST is "<import path> <Name>", as below)
    #!/bin/bash
    set -e; pkg=${1% *}; name=${1#* }
    [ "$pkg" = github.com/nats-io/nats-server/v2/server ] && cd "$(cat /src/t0.dir)" && exec /src/t0.test -test.run "^($name)\$" -test.count=1
    [ "$pkg" = github.com/nats-io/nats-server/v2/test ] && cd "$(cat /src/t1.dir)" && exec /src/t1.test -test.run "^($name)\$" -test.count=1
    exit 2

Build each test at the commit its facts below name (`git checkout COMMIT`): that is where f+ DST made it fail. The build fetches
modules with the network on; the runs are offline.

## The tests

### 1. TestJWTAccountNATSResolverWrongCreds

- TEST: `github.com/nats-io/nats-server/v2/server TestJWTAccountNATSResolverWrongCreds`
- Here: reproduced, first failure after 2543 s, replayed bit for bit
- CI's failing run: https://github.com/nats-io/nats-server/actions/runs/45223304696/job/137864842879
- CI symptom: jwt_test.go:7377: require no error, but got: stat /tmp/TestJWTAccountNATSResolverWrongCreds2926843114/006/AC5DHMJB4SMRVSWSP6BMLCYO6TBGXPCO7JCVQR2DXVUZAM6XFKXPWMGG.jwt: no such file or directory
- CI's passing run, same commit: https://github.com/nats-io/nats-server/actions/runs/45223304696/job/137873446484
- commit: 5a7a03c33d5874da6e83e1d0496527834cd8b62e

### 2. TestGatewayTLSMixedIPAndDNS

- TEST: `github.com/nats-io/nats-server/v2/test TestGatewayTLSMixedIPAndDNS`
- Here: reproduced, first failure after 1550 s, replayed bit for bit
- CI's failing run: https://github.com/nats-io/nats-server/actions/runs/45202998227/job/137842770493
- CI symptom: gateway_test.go:689: Expected 1 outbound gateway(s), got 0 (ulimit -n too low?)
- CI's passing run, same commit: https://github.com/nats-io/nats-server/actions/runs/45202998227/job/137850398391
- commit: c86d29d883f429a9c177d0b8d56da9d008bd1207

### 3. TestStressChainedSolicitWorks

- TEST: `github.com/nats-io/nats-server/v2/test TestStressChainedSolicitWorks`
- Here: reproduced, replayed bit for bit
- CI's failing run: https://github.com/nats-io/nats-server/actions/runs/44986168704/job/137097094869
- CI symptom: route_discovery_test.go:434: [/home/runner/work/nats-server/nats-server/src/github.com/nats-io/nats-server/test/route_discovery_test.go:253] Expecting 3 routes, got 2
- CI's passing run, same commit: https://github.com/nats-io/nats-server/actions/runs/44867342036/job/136733853278
- commit: a0385c9af342ffae6df28999b77a85de5423d3d6

### 4. TestJetStreamClusterDesyncAfterDiskResetDuringRollout

- TEST: `github.com/nats-io/nats-server/v2/server TestJetStreamClusterDesyncAfterDiskResetDuringRollout`
- Here: reproduced, first failure after 296 s, replayed bit for bit
- CI's failing run: https://github.com/nats-io/nats-server/actions/runs/45143988709/job/137791172837
- CI symptom: jetstream_cluster_2_test.go:9472: require no error, but got: [TEST] Expected 5 Replicas, got 4
- CI's passing run, same commit: https://github.com/nats-io/nats-server/actions/runs/45143988709/job/137814484454
- commit: e94ae7da894d41f9b0355c63bceda8437fad2564

### 5. TestJetStreamClusterLeafnodeSpokes

- TEST: `github.com/nats-io/nats-server/v2/server TestJetStreamClusterLeafnodeSpokes`
- Here: reproduced, first failure after 85 s, replayed bit for bit
- CI's failing run: https://github.com/nats-io/nats-server/actions/runs/45143988709/job/137811931384
- CI symptom: jetstream_cluster_2_test.go:502: Expected a cluster peer count of 9, got 10
- CI's passing run, same commit: https://github.com/nats-io/nats-server/actions/runs/45143988709/job/137814484454
- commit: e94ae7da894d41f9b0355c63bceda8437fad2564

### 6. TestJetStreamClusterStreamLeaderStepDown

- TEST: `github.com/nats-io/nats-server/v2/server TestJetStreamClusterStreamLeaderStepDown`
- Here: nothing found
- kind: proactive
- why: thread: stream leader step-down and re-election across a 3-node JetStream cluster while clients publish and read
- commit: 5a7a03c33d5874da6e83e1d0496527834cd8b62e

### 7. TestNRGSimpleElection

- TEST: `github.com/nats-io/nats-server/v2/server TestNRGSimpleElection`
- Here: nothing found
- kind: proactive
- why: timer: Raft leader election depends on randomized election timers and goroutine scheduling across three in-process nodes
- commit: 5a7a03c33d5874da6e83e1d0496527834cd8b62e

### 8. TestJetStreamConsumerMaxDeliveryAndServerRestart

- TEST: `github.com/nats-io/nats-server/v2/server TestJetStreamConsumerMaxDeliveryAndServerRestart`
- Here: nothing found
- kind: proactive
- why: timer: consumer redelivery (AckWait/MaxDeliver) timers racing a server restart and filestore recovery; deflaked recently
- commit: 5a7a03c33d5874da6e83e1d0496527834cd8b62e

### 9. TestJetStreamClusterAccountUsageDrifts

- TEST: `github.com/nats-io/nats-server/v2/server TestJetStreamClusterAccountUsageDrifts`
- Here: nothing found
- kind: proactive
- why: thread: account usage accounting replicated across cluster nodes via async updates; fixed as flaky recently
- commit: 5a7a03c33d5874da6e83e1d0496527834cd8b62e
