1
|
|
|
import { assert } from 'chai'; |
2
|
|
|
import { pause } from 'myrmidon'; |
3
|
|
|
import factory, { load } from '../Test'; |
4
|
|
|
|
5
|
|
|
suite('Telegram polling #no-pack'); |
6
|
|
|
|
7
|
|
|
before(async function () { |
8
|
|
|
await factory.cleanup(); |
9
|
|
|
const { Telegram } = load('lib/telegram'); |
10
|
|
|
|
11
|
|
|
const tgApps = [ |
12
|
|
|
new Telegram({ |
13
|
|
|
bot : { id: 'good_poll', token: 'polling_token' }, |
14
|
|
|
updates : { |
15
|
|
|
mode : 'polling', |
16
|
|
|
interval : '20ms' |
17
|
|
|
} |
18
|
|
|
}), |
19
|
|
|
|
20
|
|
|
new Telegram({ |
21
|
|
|
bot : { id: 'bad_poll', token: 'polling_token' }, |
22
|
|
|
updates : { |
23
|
|
|
mode : 'polling', |
24
|
|
|
interval : '20ms' |
25
|
|
|
} |
26
|
|
|
}) |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
await pause(100); |
30
|
|
|
console.log(`Started ${tgApps.length} apps`); |
|
|
|
|
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
test('Positive: tg count succeded requests', async function () { |
35
|
|
|
const onStart = await factory.findTrackLog('[*url=/getUpdates&traceId=good_poll].timestamp'); |
36
|
|
|
|
37
|
|
|
await pause(105); |
38
|
|
|
|
39
|
|
|
const onEnd = await factory.findTrackLog('[*url=/getUpdates&traceId=good_poll].timestamp'); |
40
|
|
|
const madeOnPeriod = onEnd.length - onStart.length; |
41
|
|
|
|
42
|
|
|
assert.isAtLeast(madeOnPeriod, 4); |
43
|
|
|
assert.isAtMost(madeOnPeriod, 6); |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
test('Negative: polling errors', async function () { |
47
|
|
|
const onStart = await factory.findTrackLog('[*url=/getUpdates&traceId=bad_poll].timestamp'); |
48
|
|
|
|
49
|
|
|
await pause(105); |
50
|
|
|
|
51
|
|
|
const onEnd = await factory.findTrackLog('[*url=/getUpdates&traceId=bad_poll].timestamp'); |
52
|
|
|
const madeOnPeriod = onEnd.length - onStart.length; |
53
|
|
|
|
54
|
|
|
assert.isAtLeast(madeOnPeriod, 4); |
55
|
|
|
assert.isAtMost(madeOnPeriod, 6); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
after(async function () { |
60
|
|
|
await factory.cleanup(); |
61
|
|
|
}); |
62
|
|
|
|