2021-06-15 03:12:22 +03:00
|
|
|
import { describe, it } from 'mocha'
|
|
|
|
import { expect } from 'chai'
|
2021-07-27 15:32:18 +03:00
|
|
|
import { TransportState } from '../../src'
|
2021-06-15 03:12:22 +03:00
|
|
|
import { sleep } from '../../src/utils/misc-utils'
|
2021-07-27 15:32:18 +03:00
|
|
|
import { createTestTelegramClient } from './utils'
|
2021-06-15 03:12:22 +03:00
|
|
|
|
|
|
|
require('dotenv-flow').config()
|
|
|
|
|
|
|
|
describe('e2e : idle connection', function () {
|
|
|
|
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
// 75s is to make sure ping is sent
|
|
|
|
|
|
|
|
it('75s idle to test dc', async () => {
|
2021-07-27 15:32:18 +03:00
|
|
|
const client = createTestTelegramClient()
|
2021-06-15 03:12:22 +03:00
|
|
|
|
|
|
|
await client.connect()
|
|
|
|
await sleep(75000)
|
|
|
|
|
|
|
|
expect(client.primaryConnection['_transport'].state()).eq(TransportState.Ready)
|
|
|
|
|
|
|
|
const config = await client.call({ _: 'help.getConfig' })
|
|
|
|
expect(config._).eql('config')
|
|
|
|
|
|
|
|
await client.close()
|
|
|
|
expect(client.primaryConnection['_transport'].state()).eq(TransportState.Idle)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!process.env.USER_SESSION) {
|
|
|
|
console.warn('Warning: skipping e2e idle connection test with auth (no USER_SESSION)')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
it('75s idle to test dc with auth', async () => {
|
2021-07-27 15:32:18 +03:00
|
|
|
const client = createTestTelegramClient()
|
2021-06-15 03:12:22 +03:00
|
|
|
|
|
|
|
client.importSession(process.env.USER_SESSION!)
|
|
|
|
|
|
|
|
await client.connect()
|
|
|
|
await sleep(75000)
|
|
|
|
|
|
|
|
expect(client.primaryConnection['_transport'].state()).eq(TransportState.Ready)
|
|
|
|
|
|
|
|
const config = await client.call({ _: 'help.getConfig' })
|
|
|
|
expect(config._).eql('config')
|
|
|
|
|
|
|
|
await client.close()
|
|
|
|
expect(client.primaryConnection['_transport'].state()).eq(TransportState.Idle)
|
|
|
|
})
|
|
|
|
})
|