mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-08-03 13:56:07 +00:00
49e59a3d56
* feat(backend): add OTLP trace export * fix * regenerate * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix * fix * fix --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { describe, expect, test, vi } from 'vitest';
|
|
|
|
describe('telemetry-shutdown', () => {
|
|
test('flushes telemetry once and exits on SIGTERM or SIGINT', async () => {
|
|
vi.resetModules();
|
|
const { installTelemetrySignalHandlers, isTelemetryShutdownInProgress } = await import('@/core/telemetry/telemetry-shutdown.js');
|
|
const handlers = new Map<string, () => Promise<void>>();
|
|
const processLike = {
|
|
once: vi.fn((event: string, handler: () => Promise<void>) => {
|
|
handlers.set(event, handler);
|
|
return processLike;
|
|
}),
|
|
};
|
|
const shutdownTelemetry = vi.fn().mockResolvedValue(undefined);
|
|
const exit = vi.fn();
|
|
|
|
installTelemetrySignalHandlers({ process: processLike, shutdownTelemetry, exit });
|
|
|
|
expect(processLike.once).toHaveBeenCalledWith('SIGTERM', expect.any(Function));
|
|
expect(processLike.once).toHaveBeenCalledWith('SIGINT', expect.any(Function));
|
|
expect(isTelemetryShutdownInProgress()).toBe(false);
|
|
|
|
await handlers.get('SIGTERM')!();
|
|
await handlers.get('SIGINT')!();
|
|
|
|
expect(isTelemetryShutdownInProgress()).toBe(true);
|
|
expect(shutdownTelemetry).toHaveBeenCalledTimes(1);
|
|
expect(exit).toHaveBeenCalledTimes(1);
|
|
expect(exit).toHaveBeenCalledWith(0);
|
|
});
|
|
|
|
test('exits even when telemetry shutdown rejects', async () => {
|
|
vi.resetModules();
|
|
const { installTelemetrySignalHandlers } = await import('@/core/telemetry/telemetry-shutdown.js');
|
|
const handlers = new Map<string, () => Promise<void>>();
|
|
const processLike = {
|
|
once: vi.fn((event: string, handler: () => Promise<void>) => {
|
|
handlers.set(event, handler);
|
|
return processLike;
|
|
}),
|
|
};
|
|
const exit = vi.fn();
|
|
|
|
installTelemetrySignalHandlers({
|
|
process: processLike,
|
|
shutdownTelemetry: vi.fn().mockRejectedValue(new Error('flush failed')),
|
|
exit,
|
|
});
|
|
|
|
await handlers.get('SIGINT')!();
|
|
|
|
expect(exit).toHaveBeenCalledWith(0);
|
|
});
|
|
});
|