File tree 2 files changed +42
-3
lines changed
2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -127,9 +127,11 @@ class Switch extends EventEmitter {
127
127
128
128
// Only listen on transports we actually have addresses for
129
129
return myTransports . filter ( ( ts ) => this . transports [ ts ] . filter ( myAddrs ) . length > 0 )
130
- // push Circuit to be the last proto to be dialed
131
- . sort ( ( a ) => {
132
- return a === Circuit . tag ? 1 : 0
130
+ // push Circuit to be the last proto to be dialed, and alphabetize the others
131
+ . sort ( ( a , b ) => {
132
+ if ( a === Circuit . tag ) return 1
133
+ if ( b === Circuit . tag ) return - 1
134
+ return a < b ? - 1 : 1
133
135
} )
134
136
}
135
137
Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+ 'use strict'
3
+
4
+ const chai = require ( 'chai' )
5
+ const dirtyChai = require ( 'dirty-chai' )
6
+ const expect = chai . expect
7
+ chai . use ( dirtyChai )
8
+
9
+ const Switch = require ( '../src' )
10
+
11
+ describe ( 'Switch' , ( ) => {
12
+ describe ( '.availableTransports' , ( ) => {
13
+ it ( 'should always sort circuit last' , ( ) => {
14
+ const switchA = new Switch ( { } , { } )
15
+ const transport = {
16
+ filter : ( addrs ) => addrs
17
+ }
18
+ const mockPeerInfo = {
19
+ multiaddrs : {
20
+ toArray : ( ) => [ 'a' , 'b' , 'c' ]
21
+ }
22
+ }
23
+
24
+ switchA . transports = {
25
+ Circuit : transport ,
26
+ TCP : transport ,
27
+ WebSocketStar : transport
28
+ }
29
+
30
+ expect ( switchA . availableTransports ( mockPeerInfo ) ) . to . eql ( [
31
+ 'TCP' ,
32
+ 'WebSocketStar' ,
33
+ 'Circuit'
34
+ ] )
35
+ } )
36
+ } )
37
+ } )
You can’t perform that action at this time.
0 commit comments