1
1
package all2all
2
2
3
3
import (
4
- context "context"
4
+ "context"
5
5
"flag"
6
6
"fmt"
7
7
"net"
@@ -43,19 +43,19 @@ func createReplicas(numReplicas int) ([]*replica, error) {
43
43
replicas := make ([]* replica , numReplicas )
44
44
errChan := make (chan error , numReplicas )
45
45
startedChan := make (chan struct {}, numReplicas )
46
- for i := 1 ; i <= numReplicas ; i ++ {
46
+ for i := range replicas {
47
47
lis , err := net .Listen ("tcp" , "127.0.0.1:0" )
48
48
if err != nil {
49
49
return nil , err
50
50
}
51
- replica := replica {
51
+ replica := & replica {
52
52
address : lis .Addr ().String (),
53
53
id : uint32 (i ),
54
54
lis : lis ,
55
55
server : gorums .NewServer (),
56
56
}
57
57
RegisterSampleServer (replica .server , replica )
58
- replicas [i - 1 ] = & replica
58
+ replicas [i ] = replica
59
59
go func () {
60
60
startedChan <- struct {}{}
61
61
if err := replica .serve (); err != nil {
@@ -100,8 +100,7 @@ func (r replica) WriteQC(ctx gorums.ServerCtx, request *WriteRequest) (response
100
100
func (r * replica ) createConfiguration (nodeMap map [string ]uint32 ) error {
101
101
r .mgr = NewManager (gorums .WithDialTimeout (100 * time .Millisecond ),
102
102
gorums .WithGrpcDialOptions (
103
- grpc .WithBlock (), // block until connections are made
104
- grpc .WithTransportCredentials (insecure .NewCredentials ()), // disable TLS
103
+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
105
104
),
106
105
)
107
106
_ , err := r .mgr .NewConfiguration (qspec {}, gorums .WithNodeMap (nodeMap ))
@@ -123,10 +122,9 @@ func TestGrpcDial(t *testing.T) {
123
122
t .Fatal (err )
124
123
}
125
124
for _ , replica := range replicas {
126
- ctx , cancel := context .WithTimeout (context .Background (), time .Duration (1000 )* time .Millisecond )
125
+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (10000 )* time .Millisecond )
127
126
defer cancel ()
128
127
replica .conn , err = grpc .DialContext (ctx , replica .address ,
129
- grpc .WithBlock (),
130
128
grpc .WithTransportCredentials (insecure .NewCredentials ()),
131
129
)
132
130
if err != nil {
0 commit comments