Skip to content

Commit cee8e76

Browse files
author
Cookiezaurs
committed
Making sure deletion is fully triggered
1 parent 8ea567f commit cee8e76

File tree

4 files changed

+47
-35
lines changed

4 files changed

+47
-35
lines changed

plugins/views/api/api.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi
145145
common.db.collection("app_userviews").update({"_id": {"$regex": "^" + appId + "_.*"}}, {$unset: {viewid: 1}}, {multi: true});
146146
//remove from meta
147147
common.db.collection("app_viewsmeta").remove({'_id': viewid});
148-
if (common.drillDb) {
149-
plugins.dispatch("/core/delete_granular_data", {
150-
db: "drill",
151-
collection: "drill_events",
152-
query: { a: appId + "", e: "[CLY]_view", n: viewName }
153-
});
154-
plugins.dispatch("/core/delete_granular_data", {
155-
db: "drill",
156-
collection: "drill_events",
157-
query: { a: appId + "", e: "[CLY]_action", n: viewUrl }
158-
});
159-
}
148+
149+
plugins.dispatch("/core/delete_granular_data", {
150+
db: "drill",
151+
collection: "drill_events",
152+
query: { a: appId + "", e: "[CLY]_view", n: viewName }
153+
});
154+
plugins.dispatch("/core/delete_granular_data", {
155+
db: "drill",
156+
collection: "drill_events",
157+
query: { a: appId + "", e: "[CLY]_action", n: viewUrl }
158+
});
159+
160160
plugins.dispatch("/view/delete", {appId: appId, view: viewid + ""});
161161
/** */
162162
Promise.all(deleteDocs).then(function() {

plugins/views/tests/views.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,17 @@ describe('Testing views plugin', function() {
623623
if (err) {
624624
console.log(err);
625625
}
626-
setTimeout(done, 1000 * testUtils.testScalingFactor);
626+
setTimeout(done, 500 * testUtils.testScalingFactor + 2000);
627627
});
628628
});
629+
it('Trigger deletion job to run to clean out data completely from granular data', function(done) {
630+
testUtils.triggerJobToRun("api:deletionManagerJob", function(error) {
631+
if (error) {
632+
console.log(error);
633+
}
634+
setTimeout(done, 500 * testUtils.testScalingFactor + 2000);
635+
});
636+
});
629637
verifyTotals("30days");
630638
});
631639

@@ -996,11 +1004,7 @@ describe('Testing views plugin', function() {
9961004
setTimeout(done, 100 * testUtils.testScalingFactor + waitTime);
9971005
});
9981006
});
999-
it("wait", function(done) {
1000-
setTimeout(done, 30000);
1001-
});
10021007
verifyTotals("30days");
1003-
10041008
it("End the first view(should not flush yet)", function(done) {
10051009
var data = JSON.stringify([{"key": "[CLY]_view", "count": 1, "dur": 100, "segmentation": {"name": "testviewFirst"}}]);
10061010
request
@@ -1046,14 +1050,8 @@ describe('Testing views plugin', function() {
10461050
verifyTotals("30days");
10471051
});
10481052

1049-
describe("wait", function() {
1050-
it("waiting some time for db to settle", function(done) {
1051-
setTimeout(done, 30000);
1052-
});
1053-
});
1054-
10551053
describe('reset app', function() {
1056-
it('should reset data', function(done) {
1054+
it('trigger reset endpoint', function(done) {
10571055
var params = {app_id: APP_ID, "period": "reset"};
10581056
request
10591057
.get('/i/apps/reset?api_key=' + API_KEY_ADMIN + "&args=" + JSON.stringify(params))
@@ -1067,6 +1065,11 @@ describe('Testing views plugin', function() {
10671065
setTimeout(done, 500 * testUtils.testScalingFactor);
10681066
});
10691067
});
1068+
it('Trigger deletion job to run', function(done) {
1069+
testUtils.triggerJobToRun("api:deletionManagerJob", function() {
1070+
setTimeout(done, 500 * testUtils.testScalingFactor);
1071+
});
1072+
});
10701073
});
10711074

10721075
describe('verify empty views tables', function() {
@@ -1431,7 +1434,7 @@ describe('Testing views plugin', function() {
14311434
});
14321435

14331436
describe('reset app', function() {
1434-
it('should reset data', function(done) {
1437+
it('trigger reset endpoint', function(done) {
14351438
var params = {app_id: APP_ID, "period": "reset"};
14361439
request
14371440
.get('/i/apps/reset?api_key=' + API_KEY_ADMIN + "&args=" + JSON.stringify(params))
@@ -1442,9 +1445,14 @@ describe('Testing views plugin', function() {
14421445
}
14431446
var ob = JSON.parse(res.text);
14441447
ob.should.have.property('result', 'Success');
1445-
setTimeout(done, 500 * testUtils.testScalingFactor + 2000);
1448+
setTimeout(done, 500 * testUtils.testScalingFactor);
14461449
});
14471450
});
1451+
it('Trigger deletion job to run', function(done) {
1452+
testUtils.triggerJobToRun("api:deletionManagerJob", function() {
1453+
setTimeout(done, 500 * testUtils.testScalingFactor);
1454+
});
1455+
});
14481456
});
14491457

14501458
describe('verify empty views tables', function() {

test/3.api.write/3.reset.app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ describe('Reseting app', function() {
5858
setTimeout(done, 1000 * testUtils.testScalingFactor);
5959
});
6060
});
61+
it('Trigger deletion job to run', function(done) {
62+
testUtils.triggerJobToRun("api:deletionManagerJob", function() {
63+
setTimeout(done, 5000);
64+
});
65+
});
6166
});
6267
});
6368
describe('Checking if app data reset', function() {

test/testUtils.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var should = require('should');
22
var countlyConfig = require("../frontend/express/config.js");
33
var common = require('../api/utils/common.js');
4+
const reqq = require('supertest');
45
should.Assertion.add('haveSameItems', function(other) {
56
this.params = { operator: 'to be have same items' };
67

@@ -171,19 +172,17 @@ var testUtils = function testUtils() {
171172
};
172173

173174
this.triggerJobToRun = function(jobName, callback) {
174-
this.db.collection("jobConfigs").updateOne({ jobName: jobName}, {$set: {runNow: true}}, function(err, res) {
175-
if (err) {
176-
callback(err);
177-
}
178-
else {
179-
if (res.result.nModified === 0) {
180-
callback("Job not found");
175+
var request = reqq.agent(this.url);
176+
request.get("/jobs/i?jobName=" + encodeURIComponent(jobName) + "&action=runNow&api_key=" + props.API_KEY_ADMIN)
177+
.expect(200)
178+
.end(function(err, res) {
179+
if (err) {
180+
callback(err);
181181
}
182182
else {
183183
callback();
184184
}
185-
}
186-
});
185+
});
187186
};
188187

189188
this.triggerMergeProcessing = function(callback) {

0 commit comments

Comments
 (0)