Skip to content

Commit

Permalink
feat: add check for trace
Browse files Browse the repository at this point in the history
  • Loading branch information
renanccastro committed Dec 28, 2023
1 parent a3ae6ba commit ec30c64
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 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, RegisterPublication, SubscribeAndWait } from '../_helpers/helpers';
import { GetMeteorClient, RegisterMethod, RegisterPublication, SubscribeAndWait } from '../_helpers/helpers';

/**
* We only track the observers coming from subscriptions (which have `ownerInfo`)
Expand Down Expand Up @@ -76,8 +76,27 @@ Tinytest.add('Database - Redis Oplog - Added with limit/skip', function (test) {

Meteor._sleepForMs(100);
});
Tinytest.add('Database - Redis Oplog - With protect against race condition - Check Trace', function (test) {
// in this case, the mutator will refetch the doc when publishing it
const methodId = RegisterMethod(() => TestDataRedis.update({name: 'test'}, {$set: {name: 'abv'}}));

Tinytest.add('Database - Redis Oplog - With protect against race condition', function (test) {
TestDataRedis.remove({});

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

const client = GetMeteorClient();
client.call(methodId);
Meteor._sleepForMs(1000);

let trace = Kadira.models.methods.tracerStore.currentMaxTrace[`method::${methodId}`];
const dbEvents = trace.events.filter((o) => o[0] === 'db');
test.equal(dbEvents.length, 2);

TestDataRedis.remove({});

Meteor._sleepForMs(100);
});
Tinytest.add('Database - Redis Oplog - With protect against race condition - check for finds after receiving the msg', function (test) {
// in this case, every subscriber will refetch the doc once when receiving it
const pub = RegisterPublication(() => TestDataRedis.find({name: 'test'}));

Expand Down Expand Up @@ -117,7 +136,7 @@ Tinytest.add('Database - Redis Oplog - With protect against race condition', fun
Meteor._sleepForMs(100);
});

Tinytest.add('Database - Redis Oplog - Without protect against race condition', function (test) {
Tinytest.add('Database - Redis Oplog - Without protect against race condition - no extraneous finds', function (test) {
// in this case, no subscriber will refetch the doc when receiving it
const pub = RegisterPublication(() => TestDataRedisNoRaceProtection.find({}));

Expand Down Expand Up @@ -155,6 +174,27 @@ Tinytest.add('Database - Redis Oplog - Without protect against race condition',

Meteor._sleepForMs(100);
});
Tinytest.add('Database - Redis Oplog - Without protect against race condition - Check Trace', function (test) {
// in this case, the mutator will refetch the doc when publishing it
const methodId = RegisterMethod(() => TestDataRedisNoRaceProtection.update({name: 'test'}, {$set: {name: 'abv'}}));

TestDataRedisNoRaceProtection.remove({});

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

const client = GetMeteorClient();
client.call(methodId);
Meteor._sleepForMs(1000);

let trace = Kadira.models.methods.tracerStore.currentMaxTrace[`method::${methodId}`];
const dbEvents = trace.events.filter((o) => o[0] === 'db');
test.equal(dbEvents.length, 3);
test.equal(dbEvents[2][2].func, 'fetch');

TestDataRedisNoRaceProtection.remove({});

Meteor._sleepForMs(100);
});

Tinytest.add('Database - Redis Oplog - Removed', function (test) {
const pub = RegisterPublication(() => TestData.find({}));
Expand Down

0 comments on commit ec30c64

Please sign in to comment.