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 { createServices } from '../../../services';
|
||||||
import {
|
import {
|
||||||
IAuthType,
|
IAuthType,
|
||||||
|
type IUnleashConfig,
|
||||||
type IUnleashOptions,
|
type IUnleashOptions,
|
||||||
type IUnleashServices,
|
type IUnleashServices,
|
||||||
type IUnleashStores,
|
type IUnleashStores,
|
||||||
@ -12,14 +13,15 @@ import {
|
|||||||
import dbInit, {
|
import dbInit, {
|
||||||
type ITestDb,
|
type ITestDb,
|
||||||
} from '../../../../test/e2e/helpers/database-init';
|
} from '../../../../test/e2e/helpers/database-init';
|
||||||
import { subMinutes } from 'date-fns';
|
import { startOfHour } from 'date-fns';
|
||||||
import { ApiTokenType } from '../../../types/models/api-token';
|
import { ApiTokenType } from '../../../types/models/api-token';
|
||||||
import type TestAgent from 'supertest/lib/agent';
|
import type TestAgent from 'supertest/lib/agent';
|
||||||
|
|
||||||
let db: ITestDb;
|
let db: ITestDb;
|
||||||
|
let config: IUnleashConfig;
|
||||||
|
|
||||||
async function getSetup(opts?: IUnleashOptions) {
|
async function getSetup(opts?: IUnleashOptions) {
|
||||||
const config = createTestConfig(opts);
|
config = createTestConfig(opts);
|
||||||
db = await dbInit('metrics', config.getLogger);
|
db = await dbInit('metrics', config.getLogger);
|
||||||
|
|
||||||
const services = createServices(db.stores, config, db.rawDatabase);
|
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', () => {
|
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 () => {
|
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
|
await request
|
||||||
.post('/api/client/metrics/bulk')
|
.post('/api/client/metrics/bulk')
|
||||||
.send({
|
.send({
|
||||||
@ -282,7 +286,7 @@ describe('bulk metrics', () => {
|
|||||||
featureName: 'test_feature_one',
|
featureName: 'test_feature_one',
|
||||||
appName: 'test_application',
|
appName: 'test_application',
|
||||||
environment: 'default',
|
environment: 'default',
|
||||||
timestamp: subMinutes(Date.now(), 3),
|
timestamp: startOfHour(now),
|
||||||
yes: 1000,
|
yes: 1000,
|
||||||
no: 800,
|
no: 800,
|
||||||
variants: {},
|
variants: {},
|
||||||
@ -291,7 +295,7 @@ describe('bulk metrics', () => {
|
|||||||
featureName: 'test_feature_two',
|
featureName: 'test_feature_two',
|
||||||
appName: 'test_application',
|
appName: 'test_application',
|
||||||
environment: 'development',
|
environment: 'development',
|
||||||
timestamp: subMinutes(Date.now(), 3),
|
timestamp: startOfHour(now),
|
||||||
yes: 1000,
|
yes: 1000,
|
||||||
no: 800,
|
no: 800,
|
||||||
variants: {},
|
variants: {},
|
||||||
@ -299,7 +303,9 @@ describe('bulk metrics', () => {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
.expect(202);
|
.expect(202);
|
||||||
|
|
||||||
await services.clientMetricsServiceV2.bulkAdd(); // Force bulk collection.
|
await services.clientMetricsServiceV2.bulkAdd(); // Force bulk collection.
|
||||||
|
|
||||||
const developmentReport =
|
const developmentReport =
|
||||||
await services.clientMetricsServiceV2.getClientMetricsForToggle(
|
await services.clientMetricsServiceV2.getClientMetricsForToggle(
|
||||||
'test_feature_two',
|
'test_feature_two',
|
||||||
@ -310,6 +316,7 @@ describe('bulk metrics', () => {
|
|||||||
'test_feature_one',
|
'test_feature_one',
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(developmentReport).toHaveLength(0);
|
expect(developmentReport).toHaveLength(0);
|
||||||
expect(defaultReport).toHaveLength(1);
|
expect(defaultReport).toHaveLength(1);
|
||||||
expect(defaultReport[0].yes).toBe(1000);
|
expect(defaultReport[0].yes).toBe(1000);
|
||||||
|
@ -141,6 +141,8 @@ export default async function init(
|
|||||||
await client.query(
|
await client.query(
|
||||||
`CREATE DATABASE ${testDbName} TEMPLATE ${testDBTemplateName}`,
|
`CREATE DATABASE ${testDbName} TEMPLATE ${testDBTemplateName}`,
|
||||||
);
|
);
|
||||||
|
await client.query(`ALTER DATABASE ${testDbName} SET TIMEZONE TO UTC`);
|
||||||
|
|
||||||
await client.end();
|
await client.end();
|
||||||
} else {
|
} else {
|
||||||
const db = createDb(config);
|
const db = createDb(config);
|
||||||
|
Loading…
Reference in New Issue
Block a user