<commit_before>'use strict';

/**
 * Copyright 2016 <NAME> <<EMAIL>>
 */

const {afterEach, beforeEach, describe, it} = require('mocha');
const {expect, should} = require('chai');
const Mutex = require('../lib/helper/mutex');

describe('Mutex', () => {
	/**
	 * @type {Mutex}
	 */
	let mutex;

	beforeEach('Instantiate', () => {
		mutex = new Mutex();
	});

	afterEach('Destroy', () => {
		mutex = null;
	});

	describe('Synchronous', () => {
		it('should lock', () => {
			expect(mutex.lock()).to.equal(true);
			expect(mutex.locked).to.equal(true);
		});
	});

	describe('Asynchronous', () => {
		it('should lock and unlock', () => {
			return mutex.asynchronous()
				.then(() => mutex.unlock())
				.then(() => {
					expect(mutex.locked).to.equal(false);
				});
		});

		it('should reject the lock', () => {
			return mutex.asynchronous()
				.then(() => mutex.asynchronous())
				.then(() => Promise.reject())
				.catch(() => Promise.resolve());
		});
	});

	describe('Delayed', () => {
		it('should lock', () => {
			return mutex.delayed(500);
		});

		it('should reject the lock', () => {
			return mutex.delayed(500)
				.then(() => mutex.delayed(500))
				.then(() => Promise.reject())
				.catch(() => Promise.resolve());
		});

		it('should be unlocked', (done) => {
			mutex.delayed(500)
				.then(() => {
					setTimeout(() => {
						expect(mutex.locked).to.equal(false);
						done();
					}, 500);
				});
		});
	});
});<commit_msg>Develop (#15)<commit_after>'use strict';

/**
 * Copyright 2016 <NAME> <<EMAIL>>
 */

const {afterEach, beforeEach, describe, it} = require('mocha');
const {expect, should} = require('chai');
const Mutex = require('../lib/helper/mutex');

describe('Mutex', () => {
	/**
	 * @type {Mutex}
	 */
	let mutex;

	beforeEach('Instantiate', () => {
		mutex = new Mutex();
	});

	afterEach('Destroy', () => {
		mutex = null;
	});

	describe('Synchronous', () => {
		it('should lock', () => {
			expect(mutex.lock()).to.equal(true);
			expect(mutex.locked).to.equal(true);
		});
	});

	describe('Asynchronous', () => {
		it('should lock and unlock', () => {
			return mutex.asynchronous()
				.then(() => mutex.unlock())
				.then(() => {
					expect(mutex.locked).to.equal(false);
				});
		});

		it('should reject the lock', () => {
			return mutex.asynchronous()
				.then(() => mutex.asynchronous())
				.then(() => Promise.reject())
				.catch(() => Promise.resolve());
		});
	});

	describe('Delayed', () => {
		it('should lock', () => {
			return mutex.delayed(500);
		});

		it('should reject the lock', () => {
			return mutex.delayed(500)
				.then(() => mutex.delayed(500))
				.then(() => Promise.reject())
				.catch(() => Promise.resolve());
		});

		it('should be unlocked', () => {
			return mutex.delayed(500)
				.then(() => new Promise((resolve, reject) => {
					setTimeout(() => {
						expect(mutex.locked).to.equal(false);
						resolve();
					}, 500);
				}));
		});
	});
});
{'fraction_non_alphanumeric': 0.25084976206662135, 'fraction_numerical': 0.013596193065941536, 'mean_word_length': 3.1626591230551626, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2302432', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1003, 'n_words': 176}