T-116: M1.2af — data-pipeline: read-only security-master → curate-etl input exporter (provider_mapping.tsv, listing_currencies.tsv, Pass 6 delistings.tsv from PostgreSQL) with tests and local benchmark
This commit is contained in:
parent
7c55c97c44
commit
722735c7c1
5 changed files with 159 additions and 15 deletions
|
|
@ -1249,6 +1249,74 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
expect(await readFile(lockPath, 'utf8')).toBe('{"pid":999999,"runTag":"foreign"}\n');
|
||||
});
|
||||
|
||||
test('removes .publish.lock when writing metadata fails after exclusive creation so an immediate retry succeeds', async () => {
|
||||
const outDir = await makeTempDir('curate-inputs-lock-write-fail-');
|
||||
const lockPath = join(outDir, CURATE_INPUT_PUBLISH_LOCK);
|
||||
|
||||
const makeClient = () =>
|
||||
createInMemoryQueryable({
|
||||
listings: [
|
||||
{
|
||||
listing_id: 1,
|
||||
currency: 'USD',
|
||||
listed_to: null,
|
||||
delist_reason: 'active',
|
||||
terminal_return: null,
|
||||
},
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
{
|
||||
source: 'qm',
|
||||
source_id: 'AAPL',
|
||||
valid_from: '2020-01-01',
|
||||
valid_to: null,
|
||||
listing_id: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let injected = false;
|
||||
await expect(
|
||||
exportCurateInputs(makeClient(), {
|
||||
outDir,
|
||||
fs: {
|
||||
open: async (path, flags, mode) => {
|
||||
const realHandle = await open(path, flags, mode);
|
||||
if (!injected && String(path) === lockPath && flags === 'wx') {
|
||||
injected = true;
|
||||
const wrappedHandle = Object.create(realHandle) as typeof realHandle;
|
||||
wrappedHandle.write = async () => {
|
||||
const err = new Error('Simulated ENOSPC while writing lock metadata') as NodeJS.ErrnoException;
|
||||
err.code = 'ENOSPC';
|
||||
throw err;
|
||||
};
|
||||
wrappedHandle.close = () => realHandle.close();
|
||||
return wrappedHandle;
|
||||
}
|
||||
return realHandle;
|
||||
},
|
||||
},
|
||||
})
|
||||
).rejects.toThrow('Simulated ENOSPC while writing lock metadata');
|
||||
|
||||
expect(injected).toBe(true);
|
||||
const entriesAfterFailure = await readdir(outDir);
|
||||
expect(entriesAfterFailure).not.toContain(CURATE_INPUT_PUBLISH_LOCK);
|
||||
|
||||
// Immediate retry to the same outDir must succeed without PUBLISH_LOCK_TIMEOUT.
|
||||
const retryResult = await exportCurateInputs(makeClient(), {
|
||||
outDir,
|
||||
publishLockTimeoutMs: 50,
|
||||
});
|
||||
expect(retryResult.providerMapping.rowsOut).toBe(1);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.providerMapping), 'utf8')).toBe(
|
||||
'qm\tAAPL\t2020-01-01\t\t1\n'
|
||||
);
|
||||
const entriesAfterRetry = await readdir(outDir);
|
||||
expect(entriesAfterRetry).not.toContain(CURATE_INPUT_PUBLISH_LOCK);
|
||||
});
|
||||
|
||||
test('rejects pool-like objects and invalid chunkSize', async () => {
|
||||
const outDir = await makeTempDir('curate-inputs-pool-');
|
||||
const poolLike = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue