Commit 9a9b609a authored by tobinski's avatar tobinski
Browse files

Update test and readme

parent d19c3a5b
......@@ -2,7 +2,19 @@
Magpie is a stream transformer that takes urls from a stream and requests the resource from the internet. It can handle delays between requests and concurrency.
## Usage
```js
const options = {
objectMode: true,
logger: coreMock.getLogger(),
delay: 200,
concurrent: 10
};
const magpie = new MagpieTransformer(options);
```
* logger = nconf logger instance (required)
* delay = delay between requests (default: 200)
* concurrent = concurrency (default: 10)
## Concurrency and delay
If we configure a concurrency of 10 and a delay of 200 then 10 requests are send in parallel and after finishing they will make a break for 200ms and send again. The first 10 requests hits the server in parallel and then after the response is send each callback will wait for 200ms before send again. After a while the delays between the requests are a bit more randomized.
......@@ -43,15 +43,15 @@ describe('Test magpie-transformer', () => {
logger: coreMock.getLogger(),
delay: 200,
};
const filter = new MagpieTransformer(options);
const magpie = new MagpieTransformer(options);
// listener to check output
filter.on('data', (data: any) => {
magpie.on('data', (data: any) => {
data.res.body.should.contains('ok');
done();
});
filter.write(mock);
filter.end()
magpie.write(mock);
magpie.end()
}).timeout(30000);
it('Test delay between requests if there is no concurrency', (done) => {
......@@ -61,12 +61,12 @@ describe('Test magpie-transformer', () => {
delay: 2000,
concurrent: 1
};
const filter = new MagpieTransformer(options);
const magpie = new MagpieTransformer(options);
// listener to check output
let counter = 0;
let timer;
filter.on('data', (data: any) => {
magpie.on('data', (data: any) => {
data.res.body.should.contains('ok');
if(counter === 0) {
timer = new Timer();
......@@ -84,9 +84,9 @@ describe('Test magpie-transformer', () => {
// send three mocks and measure time between results
for(let i = 0; i < 3; i++) {
const mock = JSON.stringify({url: 'http://localhost:3000/' + i});
filter.write(mock);
magpie.write(mock);
}
filter.end()
magpie.end()
}).timeout(7000);
it('Test delay between requests if there is concurrency', (done) => {
......@@ -96,12 +96,12 @@ describe('Test magpie-transformer', () => {
delay: 200,
concurrent: 10
};
const filter = new MagpieTransformer(options);
const magpie = new MagpieTransformer(options);
// listener to check output
let counter = 0;
let timer;
filter.on('data', (data: any) => {
magpie.on('data', (data: any) => {
data.res.body.should.contains('ok');
if(counter === 0) {
timer = new Timer();
......@@ -119,9 +119,9 @@ describe('Test magpie-transformer', () => {
// send three mocks and measure time between results
for(let i = 0; i < 3; i++) {
const mock = JSON.stringify({url: 'http://localhost:3000/' + i});
filter.write(mock);
magpie.write(mock);
}
filter.end()
magpie.end()
});
it('Test delay between requests if there is concurrency and allot of requests', (done) => {
......@@ -131,12 +131,12 @@ describe('Test magpie-transformer', () => {
delay: 1,
concurrent: 100
};
const filter = new MagpieTransformer(options);
const magpie = new MagpieTransformer(options);
// listener to check output
let counter = 0;
let timer;
filter.on('data', (data: any) => {
magpie.on('data', (data: any) => {
data.res.body.should.contains('ok');
if(counter === 0) {
timer = new Timer();
......@@ -154,9 +154,9 @@ describe('Test magpie-transformer', () => {
// send three mocks and measure time between results
for(let i = 0; i < 100; i++) {
const mock = JSON.stringify({url: 'http://localhost:3000/' + i});
filter.write(mock);
magpie.write(mock);
}
filter.end()
magpie.end()
}).timeout(5000);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment