-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supported run with multiple url (#260)
- Loading branch information
Showing
5 changed files
with
141 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
/** | ||
* check the url is not an empty string or empty array | ||
* @param url | ||
*/ | ||
function checkURL (url) { | ||
return (typeof url === 'string' && url) || | ||
(Array.isArray(url) && url.length > 0) | ||
} | ||
|
||
/** | ||
* | ||
* @param url | ||
* @param asArray | ||
* @returns | ||
*/ | ||
function ofURL (url, asArray) { | ||
if (Array.isArray(url)) return url | ||
|
||
if (typeof url === 'string') { | ||
return { | ||
map (fn) { | ||
if (asArray) return [fn(url)] | ||
return fn(url) | ||
} | ||
} | ||
} | ||
|
||
throw new Error('url should only be a string or an array of string') | ||
} | ||
|
||
exports.checkURL = checkURL | ||
exports.ofURL = ofURL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const test = require('tap').test | ||
const run = require('../lib/run') | ||
const helper = require('./helper') | ||
|
||
const server1 = helper.startServer({ body: 'from server1' }) | ||
const server2 = helper.startServer({ body: 'from server2' }) | ||
const server3 = helper.startServer({ body: 'from server3' }) | ||
|
||
test('should receive the message from different server', (t) => { | ||
t.plan(3) | ||
|
||
const instance = run({ | ||
url: [ | ||
server1, | ||
server2, | ||
server3 | ||
].map(server => `http://localhost:${server.address().port}`), | ||
duration: 1, | ||
connections: 3 | ||
}) | ||
|
||
let receivedServer1 = false | ||
let receivedServer2 = false | ||
let receivedServer3 = false | ||
|
||
instance.on('response', (client) => { | ||
if (!receivedServer1 && client.parser.chunk.toString().includes('from server1')) { | ||
receivedServer1 = true | ||
t.pass() | ||
} | ||
if (!receivedServer2 && client.parser.chunk.toString().includes('from server2')) { | ||
receivedServer2 = true | ||
t.pass() | ||
} | ||
if (!receivedServer3 && client.parser.chunk.toString().includes('from server3')) { | ||
receivedServer3 = true | ||
t.pass() | ||
} | ||
}) | ||
}) |