Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random tests #1353

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WORKDIR /src
ADD . /src
COPY ./static /src/server/static
WORKDIR /src/server
RUN apk add --no-cache --virtual .build-deps make gcc g++ python git libffi-dev linux-headers \
RUN apk add --no-cache --virtual .build-deps make gcc g++ python3 git libffi-dev linux-headers \
&& npm ci --unsafe-perm --production \
&& npm cache clean --force \
&& apk del .build-deps
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.buildx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ENV LD_LIBRARY_PATH /lib

WORKDIR /src/server

RUN apk add --no-cache --virtual .build-deps make gcc g++ python git libffi-dev linux-headers \
RUN apk add --no-cache --virtual .build-deps make gcc g++ python3 git libffi-dev linux-headers \
&& npm ci --unsafe-perm --production \
&& npm cache clean --force \
&& apk del .build-deps
Expand Down
11 changes: 10 additions & 1 deletion server/test/lib/device/device.calculateAggregate.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { expect } = require('chai');
const uuid = require('uuid');
const EventEmitter = require('events');
const { fake } = require('sinon');
const sinon = require('sinon');

const { fake } = sinon;
const db = require('../../../models');
const Device = require('../../../lib/device');
const Job = require('../../../lib/job');
Expand Down Expand Up @@ -29,6 +31,7 @@ const insertStates = async (fixedHour = true) => {

describe('Device.calculateAggregate', function Before() {
this.timeout(60000);
let clock;
beforeEach(async () => {
const queryInterface = db.sequelize.getQueryInterface();
await queryInterface.bulkDelete('t_device_feature_state');
Expand All @@ -41,6 +44,12 @@ describe('Device.calculateAggregate', function Before() {
},
{ where: {} },
);
clock = sinon.useFakeTimers({
now: 1635131280000,
});
});
afterEach(() => {
clock.restore();
});
it('should calculate hourly aggregate', async () => {
await insertStates(false);
Expand Down
10 changes: 10 additions & 0 deletions server/test/lib/device/device.getDeviceFeaturesAggregates.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const EventEmitter = require('events');
const { expect, assert } = require('chai');
const sinon = require('sinon');
const uuid = require('uuid');
const { fake } = require('sinon');
const db = require('../../../models');
Expand Down Expand Up @@ -28,6 +29,8 @@ const insertStates = async (intervalInMinutes) => {

describe('Device.getDeviceFeaturesAggregates', function Describe() {
this.timeout(15000);

let clock;
beforeEach(async () => {
const queryInterface = db.sequelize.getQueryInterface();
await queryInterface.bulkDelete('t_device_feature_state');
Expand All @@ -40,6 +43,13 @@ describe('Device.getDeviceFeaturesAggregates', function Describe() {
},
{ where: {} },
);

clock = sinon.useFakeTimers({
now: 1635131280000,
});
});
afterEach(() => {
clock.restore();
});
it('should return last hour states', async () => {
await insertStates(120);
Expand Down