Non-deterministic recordings files
See original GitHub issueDescription
I’m not sure how to minimally reproduce this, but using persister-fs
, I’m getting non-deterministic orderings of requests. Context: I’m working on making our polly recordings idempotent; e.g. scrubbing timestamps and auth tokens. I have everything idempotent now, but some recordings (not all) keep changing the order of requests; e.g.
[
<recording for /auth/login>,
<recording for /users>,
<recording for /users/4>,
]
will get reordered as
[
<recording for /users/4>,
<recording for /auth/login>,
<recording for /users>,
]
It seems like Persister
uses stringify
from fast-json-stable-stringify
, which should produce a deterministic JSON blob, but Persister-FS
re-parses the JSON string as JSON, which makes the JSON blob non-deterministic again:
I also don’t see a unit test for deterministic recordings?
Shareable Source
Haven’t found a minimal repro yet
Error Message & Stack Trace
See description
Config
Copy the config used to setup the Polly instance:
const { setupPolly } = require('setup-polly-jest')
setupPolly({
adapters: ['node-http'],
persister: 'fs',
logging: false,
recordFailedRequests: true,
recordIfMissing: true,
mode: recordMode,
matchRequestsBy: {
headers: {
exclude: ['Authorization'],
},
},
})
Dependencies
Copy the @pollyjs dependencies from package.json
:
{
"@pollyjs/adapter-fetch": "^2.6.3",
"@pollyjs/adapter-node-http": "^2.6.3",
"@pollyjs/core": "^2.6.3",
"@pollyjs/persister-fs": "^2.6.3",
"@pollyjs/persister-rest": "^2.6.3",
}
Relevant Links
Environment
- Mac OS (darwin 18.7.0)
- Yarn: 1.17.3
- Node: v10.16.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
From the HAR 1.2 spec:
See here
The sorting and deduping is done here: https://github.com/Netflix/pollyjs/blob/8f86fb372b6ac3e6efa36a9dee07d81d8e112847/packages/%40pollyjs/persister/src/har/log.js#L31-L45
Just as a note, Polly does depend on
startedDateTime
for features such as timing and expiration. Instead, maybe we can support a persister config option to disable sorting the entries.@pushred nope! our workaround has been working seamlessly for us (there are other idempotency problems, but this particular spot hasn’t given us any trouble)