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