Skip to content

Commit eedbaf1

Browse files
committed
add test for invalid routing table
1 parent bd853e6 commit eedbaf1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/internal/rediscovery.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import FakeConnection from './fake-connection'
2525
import lolex from 'lolex'
2626
import { int } from '../../src/integer'
2727
import { newError, SERVICE_UNAVAILABLE } from '../../lib/error'
28+
import { PROTOCOL_ERROR } from '../../src/error'
2829

2930
const PROCEDURE_NOT_FOUND_CODE = 'Neo.ClientError.Procedure.ProcedureNotFound'
3031
const DATABASE_NOT_FOUND_CODE = 'Neo.ClientError.Database.DatabaseNotFound'
@@ -173,6 +174,37 @@ describe('#unit Rediscovery', () => {
173174

174175
expect(routingTable).toEqual(null)
175176
})
177+
178+
it('should throw PROTOCOL_ERROR if the routing table is invalid', async () => {
179+
runWithClockAt(Date.now(), async () => {
180+
try {
181+
const ttl = int(123)
182+
const routers = ['bolt://localhost:7687']
183+
const writers = ['bolt://localhost:7686']
184+
const readers = []
185+
const initialAddress = '127.0.0.1'
186+
const routingContext = { context: '1234 ' }
187+
const rawRoutingTable = RawRoutingTable.ofMessageResponse(
188+
newMetadata({ ttl, routers, readers, writers })
189+
)
190+
191+
await lookupRoutingTableOnRouter({
192+
initialAddress,
193+
routingContext,
194+
rawRoutingTable
195+
})
196+
197+
fail('should not succeed')
198+
} catch (error) {
199+
expect(error).toEqual(
200+
newError(
201+
'Received no readers from router localhost:7687',
202+
PROTOCOL_ERROR
203+
)
204+
)
205+
}
206+
})
207+
})
176208
})
177209

178210
function newMetadata ({

0 commit comments

Comments
 (0)