2018-08-23 17:14:59 +02:00
|
|
|
// Copyright BigchainDB GmbH and BigchainDB contributors
|
|
|
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
|
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
|
|
|
import test from 'ava'
|
|
|
|
|
|
|
|
import {
|
|
|
|
Connection
|
|
|
|
} from '../../src'
|
|
|
|
|
|
|
|
test('Pick connection with earliest backoff time', async t => {
|
|
|
|
const path1 = 'http://localhost:9984/api/v1/'
|
2018-08-29 16:39:15 +02:00
|
|
|
const path2 = 'http://localhostwrong:9984/api/v1/'
|
2018-08-23 17:14:59 +02:00
|
|
|
|
|
|
|
// Reverse order
|
|
|
|
const conn = new Connection([path2, path1])
|
2018-08-28 14:09:26 +02:00
|
|
|
// This will trigger the 'forwardRequest' so the correct connection will be taken
|
2018-08-23 17:14:59 +02:00
|
|
|
await conn.searchAssets('example')
|
|
|
|
|
|
|
|
const connection1 = conn.transport.connectionPool[1]
|
|
|
|
|
|
|
|
t.deepEqual(conn.transport.pickConnection(), connection1)
|
|
|
|
})
|