From ec30c6413c0ce48ee86b76669ab3f22accc4152a Mon Sep 17 00:00:00 2001 From: Renan Date: Thu, 28 Dec 2023 17:27:30 -0300 Subject: [PATCH] feat: add check for trace --- tests/hijack/redis_oplog.js | 46 ++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/tests/hijack/redis_oplog.js b/tests/hijack/redis_oplog.js index 56e16547..e1704f86 100644 --- a/tests/hijack/redis_oplog.js +++ b/tests/hijack/redis_oplog.js @@ -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`) @@ -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'})); @@ -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({})); @@ -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({}));