Update mock-server, upload ci logs on failure

This commit is contained in:
Fedor Indutny 2022-02-24 17:21:56 -08:00 committed by GitHub
parent 21db47c423
commit 1d89ffcc2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 10 deletions

View file

@ -4,7 +4,14 @@
import type { PrimaryDevice } from '@signalapp/mock-server';
import { Bootstrap, debug, stats, RUN_COUNT, DISCARD_COUNT } from './fixtures';
import {
Bootstrap,
debug,
saveLogs,
stats,
RUN_COUNT,
DISCARD_COUNT,
} from './fixtures';
const CONVERSATION_SIZE = 1000; // messages
const DELAY = 50; // milliseconds
@ -94,6 +101,9 @@ const DELAY = 50; // milliseconds
};
await Promise.all([sendQueue(), measure()]);
} catch (error) {
await saveLogs(bootstrap);
throw error;
} finally {
await app.close();
await bootstrap.teardown();

View file

@ -3,10 +3,14 @@
/* eslint-disable no-await-in-loop, no-console */
import createDebug from 'debug';
import fs from 'fs/promises';
import path from 'path';
import { Bootstrap } from '../bootstrap';
export const debug = createDebug('mock:benchmarks');
export { Bootstrap } from '../bootstrap';
export { Bootstrap };
export { App } from '../playwright';
export type StatsType = {
@ -59,6 +63,19 @@ export function stats(
return result;
}
export async function saveLogs(bootstrap: Bootstrap): Promise<void> {
const { ARTIFACTS_DIR } = process.env;
if (!ARTIFACTS_DIR) {
console.error('Not saving logs. Please set ARTIFACTS_DIR env variable');
return;
}
await fs.mkdir(ARTIFACTS_DIR, { recursive: true });
const { logsDir } = bootstrap;
await fs.rename(logsDir, path.join(ARTIFACTS_DIR, 'logs'));
}
// Can happen if electron exits prematurely
process.on('unhandledRejection', reason => {
console.error('Unhandled rejection:');

View file

@ -12,6 +12,7 @@ import {
import {
Bootstrap,
debug,
saveLogs,
stats,
RUN_COUNT,
GROUP_SIZE,
@ -177,6 +178,9 @@ const LAST_MESSAGE = 'start sending messages now';
}
console.log('stats info=%j', { delta: stats(deltaList, [99, 99.8]) });
} catch (error) {
await saveLogs(bootstrap);
throw error;
} finally {
await app.close();
await bootstrap.teardown();

View file

@ -6,7 +6,14 @@ import assert from 'assert';
import { ReceiptType } from '@signalapp/mock-server';
import { Bootstrap, debug, stats, RUN_COUNT, DISCARD_COUNT } from './fixtures';
import {
Bootstrap,
debug,
saveLogs,
stats,
RUN_COUNT,
DISCARD_COUNT,
} from './fixtures';
const CONVERSATION_SIZE = 500; // messages
@ -128,6 +135,9 @@ const LAST_MESSAGE = 'start sending messages now';
}
console.log('stats info=%j', { delta: stats(deltaList, [99, 99.8]) });
} catch (error) {
await saveLogs(bootstrap);
throw error;
} finally {
await app.close();
await bootstrap.teardown();

View file

@ -4,7 +4,7 @@
import { ReceiptType } from '@signalapp/mock-server';
import { debug, Bootstrap, stats, RUN_COUNT } from './fixtures';
import { debug, Bootstrap, saveLogs, stats, RUN_COUNT } from './fixtures';
const MESSAGE_BATCH_SIZE = 1000; // messages
@ -127,6 +127,9 @@ const ENABLE_RECEIPTS = Boolean(process.env.ENABLE_RECEIPTS);
if (messagesPerSec.length !== 0) {
console.log('stats info=%j', { messagesPerSec: stats(messagesPerSec) });
}
} catch (error) {
await saveLogs(bootstrap);
throw error;
} finally {
await bootstrap.teardown();
}