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