Skip to content

Commit

Permalink
fix: flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renanccastro committed May 7, 2024
1 parent 6ab8b6f commit 10fcd7f
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions tests/hijack/redis_oplog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestData, TestDataRedis, TestDataRedisNoRaceProtection } from '../_helpers/globals';
import { GetMeteorClient, RegisterMethod, RegisterPublication, SubscribeAndWait } from '../_helpers/helpers';
import { FindMetricsForPub, GetMeteorClient, RegisterMethod, RegisterPublication, SubscribeAndWait } from '../_helpers/helpers';

/**
* We only track the observers coming from subscriptions (which have `ownerInfo`)
Expand All @@ -23,7 +23,7 @@ Tinytest.add('Database - Redis Oplog - Added', function (test) {

Meteor._sleepForMs(100);

const metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
const metrics = FindMetricsForPub(pub);

test.equal(metrics.initiallyAddedDocuments, 4);
test.equal(metrics.totalObservers, 1);
Expand All @@ -45,14 +45,14 @@ Tinytest.add('Database - Redis Oplog - Added with limit/skip', function (test) {

const client = GetMeteorClient();
const sub = SubscribeAndWait(client, pub);
let metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
let metrics = FindMetricsForPub(pub);

test.equal(metrics.polledDocuments, 1);

TestData.insert({ name: 'test' });
Meteor._sleepForMs(100);
// as the selector IS matched, redis-oplog triggers a requery
metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);
// 1 from initial subscription, 1 findOne + requery(2)
test.equal(metrics.polledDocuments, 4);

Expand All @@ -61,7 +61,7 @@ Tinytest.add('Database - Redis Oplog - Added with limit/skip', function (test) {

Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);

test.equal(metrics.initiallyAddedDocuments, 1);
test.equal(metrics.totalObservers, 1);
Expand Down Expand Up @@ -108,19 +108,19 @@ Tinytest.add('Database - Redis Oplog - With protect against race condition - che
const client2 = GetMeteorClient();
const sub = SubscribeAndWait(client, pub);
const sub2 = SubscribeAndWait(client2, pub);
let metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
let metrics = FindMetricsForPub(pub);

test.equal(metrics.polledDocuments, 1);

TestDataRedis.insert({ name: 'test' });
Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);
test.equal(metrics.polledDocuments, 2);

Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);

test.equal(metrics.initiallyAddedDocuments, 1);
test.equal(metrics.totalObservers, 2);
Expand All @@ -147,19 +147,19 @@ Tinytest.add('Database - Redis Oplog - Without protect against race condition -
const client = GetMeteorClient();
const sub = SubscribeAndWait(client, pub);
const sub2 = SubscribeAndWait(client, pub);
let metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
let metrics = FindMetricsForPub(pub);

test.equal(metrics.polledDocuments, 1);

TestDataRedisNoRaceProtection.insert({ name: 'test' });
Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);
test.equal(metrics.polledDocuments, 1);

Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);

test.equal(metrics.initiallyAddedDocuments, 1);
test.equal(metrics.totalObservers, 2);
Expand Down Expand Up @@ -214,7 +214,7 @@ Tinytest.add('Database - Redis Oplog - Removed', function (test) {

Meteor._sleepForMs(100);

let metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
let metrics = FindMetricsForPub(pub);

test.equal(metrics.totalObservers, 1);
test.equal(metrics.liveRemovedDocuments, 1);
Expand All @@ -223,7 +223,7 @@ Tinytest.add('Database - Redis Oplog - Removed', function (test) {

Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);

test.equal(metrics.totalObservers, 1);
test.equal(metrics.liveRemovedDocuments, 3);
Expand Down Expand Up @@ -252,7 +252,7 @@ Tinytest.add('Database - Redis Oplog - Changed', function (test) {

Meteor._sleepForMs(100);

let metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
let metrics = FindMetricsForPub(pub);

test.equal(metrics.totalObservers, 1);
test.equal(metrics.liveChangedDocuments, 1);
Expand All @@ -261,7 +261,7 @@ Tinytest.add('Database - Redis Oplog - Changed', function (test) {

Meteor._sleepForMs(100);

metrics = Kadira.models.pubsub._getMetrics(new Date(), pub);
metrics = FindMetricsForPub(pub);

test.equal(metrics.totalObservers, 1);
test.equal(metrics.liveChangedDocuments, 4);
Expand Down

0 comments on commit 10fcd7f

Please sign in to comment.