update CHANGELOG.md
[websub-hub] / test-e2e / test-many.js
1 'use strict';
2
3 const assert = require('assert');
4 const uuid = require('uuid');
5 const FakeServersClient = require('./fake-servers-client');
6
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}/`;
13
14 const client = new FakeServersClient(listenAddress, subscriberPort, topicPort);
15
16 async function newTopic() {
17 const id = uuid.v4();
18 await client.topicSet(id, { hubUrl });
19 console.log('created fake topic', id);
20 return id;
21 }
22
23 async function newSubscriber() {
24 const id = uuid.v4();
25 await client.subscriberSetVerify(id);
26 console.log('created fake subscriber', id);
27 return id;
28 }
29
30 (async function main() {
31 const topicId = await newTopic();
32 const numSubscribers = 100;
33
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);
37
38 console.log('done');
39 })().catch((e) => {
40 console.log(e);
41 throw e;
42 });