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

Function testLocked

test/parallel/test-fs-promises-file-handle-pullsync.js:240–259  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238// =============================================================================
239
240async function testLocked() {
241 const filePath = path.join(tmpDir, 'pullsync-locked.txt');
242 fs.writeFileSync(filePath, 'lock test');
243
244 const fh = await open(filePath, 'r');
245 const iter = fh.pullSync()[Symbol.iterator]();
246 iter.next(); // Start iteration, handle is locked
247
248 assert.throws(() => fh.pullSync(), {
249 code: 'ERR_INVALID_STATE',
250 });
251
252 assert.throws(() => fh.pull(), {
253 code: 'ERR_INVALID_STATE',
254 });
255
256 // Finish iteration to unlock
257 while (!iter.next().done) { /* drain */ }
258 await fh.close();
259}
260
261// =============================================================================
262// Empty file

Calls 6

openFunction · 0.70
nextMethod · 0.65
closeMethod · 0.65
joinMethod · 0.45
writeFileSyncMethod · 0.45
pullMethod · 0.45

Tested by

no test coverage detected