<commit_before>/* global describe, it, beforeEach */
/* jslint node: true, esnext: true */

"use strict";

const kronosStep = require('kronos-step');
//const endpointImpls = kronosStep.endpointImplementation;

const channel = require('../lib/channel');
const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should();

const requestGenerator = function* () {
	for (let i = 1;; i++) {
		yield {
			info: {
				name: `send from output #${i}`
			},
			stream: `a stream ${i}`
		};
	}
};

const manager = {};

describe('channel', function () {
	describe('in(passive) -> out(active)', function () {
		let es;
		let chl;

		beforeEach(function () {
			es = {
				"input": kronosStep.createEndpoint("input", {
					direction: "in(passive)"
				}),
				"output": kronosStep.createEndpoint("output", {
					direction: "out(active)"
				})
			};

			chl = channel.create({
				name: "a"
			}, es.input, {
				name: "b"
			}, es.output);
		});

		it('endpoints created', function () {
			assert(chl.endpointA);
			assert(chl.endpointB);
		});

		it('has a name', function () {
			assert(chl.name === 'a/input->b/output');
		});

		it('requests passing through generator', function () {
			chl.endpointA.initialize(manager, requestGenerator);
			const input = chl.endpointB.initialize(manager);

			let i = 1;

			for (let request of input) {
				//console.log(`got: ${JSON.stringify(request)}`);

				assert(request.info.name === `send from output #${i}`, `#${i} info attributes present`);
				assert(request.stream === `a stream ${i}`, `stream ${i} present`);
				i++;
				if (i > 5) break;
			}
		});
	});

	describe('in(passive) -> out(passive)', function () {
		let es;
		let chl;

		beforeEach(function () {
			es = {
				"input": kronosStep.createEndpoint("input", {
					direction: "in(passive)"
				}),
				"output": kronosStep.createEndpoint("output", {
					direction: "out(passive)"
				})
			};

			chl = channel.create({
				name: "a"
			}, es.input, {
				name: "b"
			}, es.output);
		});

		it('endpoints created', function () {
			assert(chl.endpointA);
			assert(chl.endpointB);
		});

		it('has a name', function () {
			assert(chl.name === 'a/input->b/output');
		});

		it('requests passing through generator', function () {
			const input = chl.endpointA.initialize(manager);

			//console.log(`input: ${input}`);

			let i;

			for (i = 1; i < 10; i++) {
				input.next({
					info: {
						name: `send from output #${i}`
					},
					stream: `a stream ${i}`
				});
			}

			const output = chl.endpointB.initialize(manager);

			i = 1;

			for (let request of output) {
				//console.log(`got: ${JSON.stringify(request)}`);

				assert(request.info.name === `send from output #${i}`, `#${i} info attributes present`);
				assert(request.stream === `a stream ${i}`, `stream ${i} present`);
				i++;
				if (i > 5) break;
			}
		});
	});
});
<commit_msg>test(channel): gardening only - still not working<commit_after>/* global describe, it, beforeEach */
/* jslint node: true, esnext: true */

"use strict";

const kronosStep = require('kronos-step');
//const endpointImpls = kronosStep.endpointImplementation;

const channel = require('../lib/channel');
const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should();

const requestGenerator = function* () {
	for (let i = 1;; i++) {
		yield {
			info: {
				name: `send from output #${i}`
			},
			stream: `a stream ${i}`
		};
	}
};

const manager = {};

describe('channel', function () {
	describe('in(passive) -> out(active)', function () {
		let es;
		let chl;

		beforeEach(function () {
			es = {
				"input": kronosStep.createEndpoint("input", {
					direction: "in(passive)"
				}),
				"output": kronosStep.createEndpoint("output", {
					direction: "out(active)"
				})
			};

			chl = channel.create({
				name: "a"
			}, es.input, {
				name: "b"
			}, es.output);
		});

		it('has endpoints', function () {
			assert.isDefined(chl.endpointA);
			assert.isDefined(chl.endpointB);
		});

		it('has a name', function () {
			assert.equal(chl.name, 'a/input->b/output');
		});

		it('requests passing through generator', function () {
			chl.endpointA.initialize(manager, requestGenerator);
			const input = chl.endpointB.initialize(manager);

			let i = 1;

			for (let request of input) {
				console.log(`got: ${JSON.stringify(request)}`);

				assert(request.info.name === `send from output #${i}`, `#${i} info attributes present`);
				assert(request.stream === `a stream ${i}`, `stream ${i} present`);
				i++;
				if (i > 5) break;
			}
		});
	});

	describe('in(passive) -> out(passive)', function () {
		let es;
		let chl;

		beforeEach(function () {
			es = {
				"input": kronosStep.createEndpoint("input", {
					direction: "in(passive)"
				}),
				"output": kronosStep.createEndpoint("output", {
					direction: "out(passive)"
				})
			};

			chl = channel.create({
				name: "a"
			}, es.input, {
				name: "b"
			}, es.output);
		});

		it('has endpoints', function () {
			assert.isDefined(chl.endpointA);
			assert.isDefined(chl.endpointB);
		});

		it('has a name', function () {
			assert.equal(chl.name, 'a/input->b/output');
		});

		it('requests passing through generator', function () {
			const input = chl.endpointA.initialize(manager);

			//console.log(`input: ${input}`);

			let i;

			for (i = 1; i < 10; i++) {
				input.next({
					info: {
						name: `send from output #${i}`
					},
					stream: `a stream ${i}`
				});
			}

			const output = chl.endpointB.initialize(manager);

			i = 1;

			for (let request of output) {
				//console.log(`got: ${JSON.stringify(request)}`);

				assert(request.info.name === `send from output #${i}`, `#${i} info attributes present`);
				assert(request.stream === `a stream ${i}`, `stream ${i} present`);
				i++;
				if (i > 5) break;
			}
		});
	});
});

{'fraction_non_alphanumeric': 0.19647696476964768, 'fraction_numerical': 0.0027100271002710027, 'mean_word_length': 3.089335180055402, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4470191', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2028, 'n_words': 467}