This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cbl-webhook_events_not_posted.js
139 lines (121 loc) · 3.69 KB
/
cbl-webhook_events_not_posted.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var launcher = require("../lib/launcher"),
spawn = require('child_process').spawn,
coax = require("coax"),
async = require("async"),
common = require("../tests/common"),
util = require("util"),
conf_file = process.env.CONF_FILE || 'local',
config = require('../config/' + conf_file),
test = require("tap").test,
test_time = process.env.TAP_TIMEOUT || 30000,
test_conf = {timeout: test_time * 1000};
var server, sg, gateway,
// local dbs
dbs = ["webhook_events"];
var numDocs=parseInt(config.numDocs) || 100;
var timeoutReplication = 5000;
if (config.provides=="android" || config.DbUrl.indexOf("http") > -1) timeoutReplication = 500 * numDocs;
var module_name = '\r\n\r\n>>>>>>>>>>>>>>>>>>>' + module.filename.slice(__filename.lastIndexOf(require('path').sep)
+ 1, module.filename.length - 3) + '.js ' + new Date().toString()
console.time(module_name);
console.error(module_name)
test("kill LiteServ", function (t) {
if (config.provides == "android") {
spawn('adb', ["shell", "am", "force-stop", "com.couchbase.liteservandroid"])
setTimeout(function () {
t.end()
}, 3000)
} else {
t.end()
}
})
// start client endpoint
test("start test client", function (t) {
common.launchClient(t, function (_server) {
server = _server
coax([server, "_session"], function (err, ok) {
try {
console.error(ok)
t.equals(ok.ok, true, "api exists")
if (ok.ok == true) {
t.end()
}
} catch (err) {
console.error(err, "will restart LiteServ...")
common.launchClient(t, function (_server) {
server = _server
t.end()
}, setTimeout(function () {
}, 3000))
}
})
})
})
// kill sync gateway
test("kill syncgateway", function (t) {
common.kill_sg(t, function () {
},
setTimeout(function(){
t.end();
}, 2000))
})
// start sync gateway
test("start syncgateway", function (t) {
common.launchSG(t, function (_sg) {
sg = _sg
gateway = sg.url
t.end()
})
})
// create all dbs
test("create test databases", function(t){
common.createDBs(t, dbs)
})
// setup push replication to gateway
test("set push replication to gateway", function(t){
var i = 0
var gatewayDB = coax([gateway, config.DbBucket]).pax().toString()
if (config.provides=="android") gatewayDB = gatewayDB.replace("localhost", "10.0.2.2")
async.series([
function(sgpush){
async.mapSeries(dbs, function(db, cb){
coax([server, "_replicate"]).post({
source : db,
target : gatewayDB,
continuous : true,
}, function(err, ok){
t.equals(err, null,
util.inspect({_replicate : db+" -> " + gatewayDB}))
i++
cb(err, ok)
})
}, sgpush)
}], function(err, json){
t.false(err, "setup push replication to gateway")
t.end()
})
})
test("load databases", test_conf, function(t){
common.createDBDocs(t, {numdocs : numDocs, dbs : dbs})
})
test("verify replicated num-docs=" + numDocs, test_conf, function(t){
common.verifySGNumDocs(t, [sg], numDocs)
})
test("doc update on SG", test_conf, function(t){
// start updating docs
common.updateSGDocs(t, {dbs : [sg],numrevs : 1})
})
test("doc update on liteServ", test_conf, function(t){
// start updating docs
console.log("start updating SG docs... 10 numRevs")
//setInterval(common.updateDBDocs,5000,t,{dbs:dbs,numrevs:10,numdocs:numDocs})
common.updateDBDocs(t, {dbs : dbs,
numrevs : 10,
numdocs : numDocs})
})
test("done", function(t){
common.cleanup(t, function(json){
sg.kill()
t.end()
}, console.timeEnd(module_name));
});