@microsoft.azure/async-io
Version:
Promisify'd asnyc wrappers (for Azure Open Source Projects)
71 lines • 2.86 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const mocha_typescript_1 = require("mocha-typescript");
const assert = require("assert");
const asyncio = require("../main");
// ensure
let AsyncIO = class AsyncIO {
async "Locking simple file"() {
const release = await asyncio.Lock.exclusive(__filename);
assert.equal(await asyncio.Lock.check(__filename), true);
release();
assert.equal(await asyncio.Lock.check(__filename), false);
}
async "Locking - does lock deny access"() {
const release = await asyncio.Lock.exclusive(__filename);
let threw = false;
try {
const release2 = await asyncio.Lock.exclusive(__filename);
}
catch (e) {
threw = true;
}
assert.equal(threw, true);
release();
assert.equal(await asyncio.Lock.check(__filename), false);
}
async "ReadLock simple file"() {
// it should be not locked now
assert.equal(await asyncio.Lock.check(__filename), false);
const release1 = await asyncio.Lock.read(__filename);
const release2 = await asyncio.Lock.read(__filename);
const release3 = await asyncio.Lock.read(__filename);
// it should be locked now
assert.equal(await asyncio.Lock.check(__filename), true);
let threw = false;
try {
// should fail getting write lock here.
await asyncio.Lock.exclusive(__filename);
}
catch (e) {
threw = true;
}
assert.equal(threw, true);
release1();
release2();
release3();
const release4 = await asyncio.Lock.exclusive(__filename);
assert.equal(await asyncio.Lock.check(__filename), true);
release4();
assert.equal(await asyncio.Lock.check(__filename), false);
}
};
__decorate([
mocha_typescript_1.test
], AsyncIO.prototype, "Locking simple file", null);
__decorate([
mocha_typescript_1.test
], AsyncIO.prototype, "Locking - does lock deny access", null);
__decorate([
mocha_typescript_1.test
], AsyncIO.prototype, "ReadLock simple file", null);
AsyncIO = __decorate([
mocha_typescript_1.suite
], AsyncIO);
//# sourceMappingURL=test-locks.js.map