mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
fix: flaky test once an hour (#9615)
This test was flaky once an hour because subminutes 3 made it fall into the wrong bucket when tests were run exactly or minutes after the our had passed. Also, the databases created were created with the system clock. I altered it to be explicitly UTC.
This commit is contained in:
parent
380d2c2c5d
commit
832b651f5b
@ -5,6 +5,7 @@ import { clientMetricsSchema } from '../shared/schema';
|
||||
import { createServices } from '../../../services';
|
||||
import {
|
||||
IAuthType,
|
||||
type IUnleashConfig,
|
||||
type IUnleashOptions,
|
||||
type IUnleashServices,
|
||||
type IUnleashStores,
|
||||
@ -12,14 +13,15 @@ import {
|
||||
import dbInit, {
|
||||
type ITestDb,
|
||||
} from '../../../../test/e2e/helpers/database-init';
|
||||
import { subMinutes } from 'date-fns';
|
||||
import { startOfHour } from 'date-fns';
|
||||
import { ApiTokenType } from '../../../types/models/api-token';
|
||||
import type TestAgent from 'supertest/lib/agent';
|
||||
|
||||
let db: ITestDb;
|
||||
let config: IUnleashConfig;
|
||||
|
||||
async function getSetup(opts?: IUnleashOptions) {
|
||||
const config = createTestConfig(opts);
|
||||
config = createTestConfig(opts);
|
||||
db = await dbInit('metrics', config.getLogger);
|
||||
|
||||
const services = createServices(db.stores, config, db.rawDatabase);
|
||||
@ -273,6 +275,8 @@ test('should return 204 if metrics are disabled by feature flag', async () => {
|
||||
|
||||
describe('bulk metrics', () => {
|
||||
test('filters out metrics for environments we do not have access for. No auth setup so we can only access default env', async () => {
|
||||
const now = new Date();
|
||||
|
||||
await request
|
||||
.post('/api/client/metrics/bulk')
|
||||
.send({
|
||||
@ -282,7 +286,7 @@ describe('bulk metrics', () => {
|
||||
featureName: 'test_feature_one',
|
||||
appName: 'test_application',
|
||||
environment: 'default',
|
||||
timestamp: subMinutes(Date.now(), 3),
|
||||
timestamp: startOfHour(now),
|
||||
yes: 1000,
|
||||
no: 800,
|
||||
variants: {},
|
||||
@ -291,7 +295,7 @@ describe('bulk metrics', () => {
|
||||
featureName: 'test_feature_two',
|
||||
appName: 'test_application',
|
||||
environment: 'development',
|
||||
timestamp: subMinutes(Date.now(), 3),
|
||||
timestamp: startOfHour(now),
|
||||
yes: 1000,
|
||||
no: 800,
|
||||
variants: {},
|
||||
@ -299,7 +303,9 @@ describe('bulk metrics', () => {
|
||||
],
|
||||
})
|
||||
.expect(202);
|
||||
|
||||
await services.clientMetricsServiceV2.bulkAdd(); // Force bulk collection.
|
||||
|
||||
const developmentReport =
|
||||
await services.clientMetricsServiceV2.getClientMetricsForToggle(
|
||||
'test_feature_two',
|
||||
@ -310,6 +316,7 @@ describe('bulk metrics', () => {
|
||||
'test_feature_one',
|
||||
1,
|
||||
);
|
||||
|
||||
expect(developmentReport).toHaveLength(0);
|
||||
expect(defaultReport).toHaveLength(1);
|
||||
expect(defaultReport[0].yes).toBe(1000);
|
||||
|
@ -141,6 +141,8 @@ export default async function init(
|
||||
await client.query(
|
||||
`CREATE DATABASE ${testDbName} TEMPLATE ${testDBTemplateName}`,
|
||||
);
|
||||
await client.query(`ALTER DATABASE ${testDbName} SET TIMEZONE TO UTC`);
|
||||
|
||||
await client.end();
|
||||
} else {
|
||||
const db = createDb(config);
|
||||
|
Loading…
Reference in New Issue
Block a user