MCPcopy Create free account
hub / github.com/nodejs/node / testUnlockAfterFail

Function testUnlockAfterFail

test/parallel/test-fs-promises-file-handle-writer.js:219–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

217// =============================================================================
218
219async function testUnlockAfterFail() {
220 const filePath = path.join(tmpDir, 'writer-unlock-fail.txt');
221 const fh = await open(filePath, 'w');
222
223 const w1 = fh.writer();
224 await w1.write(Buffer.from('failed'));
225 await w1.fail(new Error('test'));
226
227 // Should work - handle is unlocked
228 const w2 = fh.writer();
229 await w2.write(Buffer.from('recovered'));
230 await w2.end();
231 await fh.close();
232
233 // 'recovered' is appended after 'failed' at current file offset
234 const content = fs.readFileSync(filePath, 'utf8');
235 assert.ok(content.startsWith('failed'));
236 assert.ok(content.includes('recovered'));
237}
238
239// =============================================================================
240// Write after end/fail rejects

Calls 11

writerMethod · 0.80
includesMethod · 0.80
openFunction · 0.70
closeMethod · 0.65
joinMethod · 0.45
writeMethod · 0.45
fromMethod · 0.45
failMethod · 0.45
endMethod · 0.45
readFileSyncMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected