3 const assert
= require('assert');
4 const uuid
= require('uuid');
5 const FakeServersClient
= require('./fake-servers-client');
7 const subscriberPort
= process
.env
.FAKE_SUBSCRIBER_PORT
|| 9876;
8 const topicPort
= process
.env
.FAKE_TOPIC_PORT
|| 9875;
9 const listenAddress
= process
.env
.FAKE_LISTEN_ADDR
|| '127.0.0.1';
10 const hubAddress
= process
.env
.LISTEN_ADDR
|| '127.0.0.1';
11 const hubPort
= process
.env
.PORT
|| 4001;
12 const hubUrl
= `http://${hubAddress}:${hubPort}/`;
14 const client
= new FakeServersClient(listenAddress
, subscriberPort
, topicPort
);
16 async
function newTopic() {
18 await client
.topicSet(id
, { hubUrl
});
19 console
.log('created fake topic', id
);
23 async
function newSubscriber() {
25 await client
.subscriberSetVerify(id
);
26 console
.log('created fake subscriber', id
);
30 (async
function main() {
31 const topicId
= await
newTopic();
32 const numSubscribers
= 100;
34 const subIds
= await Promise
.all([...Array(numSubscribers
)].map(() => newSubscriber()));
35 const results
= await Promise
.all(subIds
.map((id
) => client
.subscribe(hubUrl
, id
, topicId
)));
36 console
.log('results', results
);