Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
e4a617ec
Commit
e4a617ec
authored
Jun 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a094e447
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
45 deletions
+41
-45
go/neo/server/cluster_test.go
go/neo/server/cluster_test.go
+8
-14
go/xcommon/xnet/pipenet/pipenet.go
go/xcommon/xnet/pipenet/pipenet.go
+17
-8
go/xcommon/xnet/pipenet/pipenet_test.go
go/xcommon/xnet/pipenet/pipenet_test.go
+15
-22
go/xcommon/xtesting/xtesting.go
go/xcommon/xtesting/xtesting.go
+1
-1
No files found.
go/neo/server/cluster_test.go
View file @
e4a617ec
...
...
@@ -121,6 +121,11 @@ func TestMasterStorage(t *testing.T) {
//net := xnet.NetTrace(pipenet.New(""), tracer) // test network
net
:=
pipenet
.
New
(
"testnet"
)
// test network
// syntatic shortcut for net tx events
nettx
:=
func
(
src
,
dst
,
pkt
string
)
*
xnet
.
TraceTx
{
return
&
xnet
.
TraceTx
{
Src
:
net
.
Addr
(
src
),
Dst
:
net
.
Addr
(
dst
),
Pkt
:
[]
byte
(
pkt
)}
}
Mhost
:=
xnet
.
NetTrace
(
net
.
Host
(
"m"
),
tracer
)
Shost
:=
xnet
.
NetTrace
(
net
.
Host
(
"s"
),
tracer
)
...
...
@@ -146,7 +151,7 @@ func TestMasterStorage(t *testing.T) {
// start storage
zstor
:=
xfs1stor
(
"../../zodb/storage/fs1/testdata/1.fs"
)
S
:=
NewStorage
(
"abc1"
,
Maddr
,
Saddr
,
ne
t
,
zstor
)
S
:=
NewStorage
(
"abc1"
,
Maddr
,
Saddr
,
Shos
t
,
zstor
)
Sctx
,
Scancel
:=
context
.
WithCancel
(
context
.
Background
())
wg
.
Gox
(
func
()
{
err
:=
S
.
Run
(
Sctx
)
...
...
@@ -159,21 +164,10 @@ func TestMasterStorage(t *testing.T) {
tc
.
Expect
(
&
xnet
.
TraceDial
{
Dst
:
"0"
})
//tc.ExpectNetDial("0")
//tc.Expect(xnet.NetTx{Src: "2c", Dst: "2s", Pkt: []byte("\x00\x00\x00\x01")})
//tc.Expect(nettx("2c", "2s", "\x00\x00\x00\x01"))
// handshake
tc
.
Expect
(
nettx
(
"s:1"
,
"m:1"
,
"
\x00\x00\x00\x01
"
))
tc
.
Expect
(
nettx
(
"m:1"
,
"s:1"
,
"
\x00\x00\x00\x01
"
))
//tc.ExpectNetTx("2c", "2s", "\x00\x00\x00\x01") // handshake
//tc.ExpectNetTx("2s", "2c", "\x00\x00\x00\x01")
tc
.
ExpectPar
(
//&xnet.TraceTx{Src: "2c", Dst: "2s", Pkt: []byte("\x00\x00\x00\x01")},
//&xnet.TraceTx{Src: "2s", Dst: "2c", Pkt: []byte("\x00\x00\x00\x01")},)
&
xnet
.
TraceTx
{
Src
:
&
pipenet
.
Addr
{
Net
:
"pipe"
,
Port
:
2
,
Endpoint
:
0
},
Dst
:
&
pipenet
.
Addr
{
Net
:
"pipe"
,
Port
:
2
,
Endpoint
:
1
},
Pkt
:
[]
byte
(
"
\x00\x00\x00\x01
"
)},
nettx
(
"s:1"
,
"m:1"
,
"
\x00\x00\x00\x01
"
),
// handshake
nettx
(
"m:1"
,
"s:1"
,
"
\x00\x00\x00\x01
"
),
)
//&xnet.TraceTx{Src: "2s", Dst: "2c", Pkt: []byte("\x00\x00\x00\x01")},)
// XXX temp
...
...
go/xcommon/xnet/pipenet/pipenet.go
View file @
e4a617ec
...
...
@@ -151,21 +151,17 @@ func (n *Network) Host(name string) *Host {
// resolveAddr resolves addr on the network from the host point of view
// must be called with Network.mu held
func
(
h
*
Host
)
resolveAddr
(
addr
string
)
(
host
*
Host
,
port
int
,
err
error
)
{
hoststr
,
portstr
,
err
:=
net
.
SplitHostPort
(
addr
)
a
,
err
:=
h
.
network
.
ParseAddr
(
addr
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
port
,
err
=
strconv
.
Atoi
(
portstr
)
if
err
!=
nil
||
port
<
0
{
return
nil
,
0
,
&
net
.
AddrError
{
Err
:
"invalid"
,
Addr
:
addr
}
}
// local host if host name omitted
if
hoststr
==
""
{
hoststr
=
h
.
name
if
a
.
Host
==
""
{
a
.
Host
=
h
.
name
}
host
=
h
.
network
.
hostMap
[
hoststr
]
host
=
h
.
network
.
hostMap
[
a
.
Host
]
if
host
==
nil
{
return
nil
,
0
,
&
net
.
AddrError
{
Err
:
"no such host"
,
Addr
:
addr
}
}
...
...
@@ -396,6 +392,19 @@ func (sk *socket) addr() *Addr {
func
(
a
*
Addr
)
Network
()
string
{
return
a
.
Net
}
func
(
a
*
Addr
)
String
()
string
{
return
net
.
JoinHostPort
(
a
.
Host
,
strconv
.
Itoa
(
a
.
Port
))
}
// ParseAddr parses addr into pipenet address
func
(
n
*
Network
)
ParseAddr
(
addr
string
)
(
*
Addr
,
error
)
{
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
port
,
err
:=
strconv
.
Atoi
(
portstr
)
if
err
!=
nil
||
port
<
0
{
return
nil
,
&
net
.
AddrError
{
Err
:
"invalid port"
,
Addr
:
addr
}
}
return
&
Addr
{
Net
:
n
.
Network
(),
Host
:
host
,
Port
:
port
},
nil
}
// Addr returns address where listener is accepting incoming connections
func
(
l
*
listener
)
Addr
()
net
.
Addr
{
return
l
.
socket
.
addr
()
...
...
go/xcommon/xnet/pipenet/pipenet_test.go
View file @
e4a617ec
...
...
@@ -22,7 +22,6 @@ import (
"fmt"
"io"
"net"
"strconv"
"reflect"
"testing"
...
...
@@ -89,54 +88,48 @@ func assertEq(t *testing.T, a, b interface{}) {
func
TestPipeNet
(
t
*
testing
.
T
)
{
pnet
:=
New
(
"t"
)
addr
:=
func
(
hostport
string
)
*
Addr
{
// XXX -> Network.ParseAddr ?
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
hostport
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
port
,
err
:=
strconv
.
Atoi
(
portstr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
&
Addr
{
Net
:
pnet
.
Network
(),
Host
:
host
,
Port
:
port
}
xaddr
:=
func
(
addr
string
)
*
Addr
{
a
,
err
:=
pnet
.
ParseAddr
(
addr
)
exc
.
Raiseif
(
err
)
return
a
}
hα
:=
pnet
.
Host
(
"α"
)
hβ
:=
pnet
.
Host
(
"β"
)
_
,
err
:=
hα
.
Dial
(
context
.
Background
(),
":0"
)
assertEq
(
t
,
err
,
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
"pipet"
,
Addr
:
addr
(
"α:0"
),
Err
:
errConnRefused
})
assertEq
(
t
,
err
,
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
"pipet"
,
Addr
:
x
addr
(
"α:0"
),
Err
:
errConnRefused
})
l1
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l1
.
Addr
(),
addr
(
"α:0"
))
assertEq
(
t
,
l1
.
Addr
(),
x
addr
(
"α:0"
))
wg
:=
&
xsync
.
WorkGroup
{}
wg
.
Gox
(
func
()
{
c1s
:=
xaccept
(
l1
)
assertEq
(
t
,
c1s
.
LocalAddr
(),
addr
(
"α:1"
))
assertEq
(
t
,
c1s
.
RemoteAddr
(),
addr
(
"β:0"
))
assertEq
(
t
,
c1s
.
LocalAddr
(),
x
addr
(
"α:1"
))
assertEq
(
t
,
c1s
.
RemoteAddr
(),
x
addr
(
"β:0"
))
assertEq
(
t
,
xread
(
c1s
),
"ping"
)
xwrite
(
c1s
,
"pong"
)
c2s
:=
xaccept
(
l1
)
assertEq
(
t
,
c2s
.
LocalAddr
(),
addr
(
"α:2"
))
assertEq
(
t
,
c2s
.
RemoteAddr
(),
addr
(
"β:1"
))
assertEq
(
t
,
c2s
.
LocalAddr
(),
x
addr
(
"α:2"
))
assertEq
(
t
,
c2s
.
RemoteAddr
(),
x
addr
(
"β:1"
))
assertEq
(
t
,
xread
(
c2s
),
"hello"
)
xwrite
(
c2s
,
"world"
)
})
c1c
:=
xdial
(
hβ
,
"α:0"
)
assertEq
(
t
,
c1c
.
LocalAddr
(),
addr
(
"β:0"
))
assertEq
(
t
,
c1c
.
RemoteAddr
(),
addr
(
"α:1"
))
assertEq
(
t
,
c1c
.
LocalAddr
(),
x
addr
(
"β:0"
))
assertEq
(
t
,
c1c
.
RemoteAddr
(),
x
addr
(
"α:1"
))
xwrite
(
c1c
,
"ping"
)
assertEq
(
t
,
xread
(
c1c
),
"pong"
)
c2c
:=
xdial
(
hβ
,
"α:0"
)
assertEq
(
t
,
c2c
.
LocalAddr
(),
addr
(
"β:1"
))
assertEq
(
t
,
c2c
.
RemoteAddr
(),
addr
(
"α:2"
))
assertEq
(
t
,
c2c
.
LocalAddr
(),
x
addr
(
"β:1"
))
assertEq
(
t
,
c2c
.
RemoteAddr
(),
x
addr
(
"α:2"
))
xwrite
(
c2c
,
"hello"
)
assertEq
(
t
,
xread
(
c2c
),
"world"
)
...
...
@@ -144,5 +137,5 @@ func TestPipeNet(t *testing.T) {
xwait
(
wg
)
l2
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l2
.
Addr
(),
addr
(
"α:3"
))
assertEq
(
t
,
l2
.
Addr
(),
x
addr
(
"α:3"
))
}
go/xcommon/xtesting/xtesting.go
View file @
e4a617ec
...
...
@@ -139,7 +139,7 @@ loop:
// found matching event - good
eventExpectV
=
append
(
eventExpectV
[
:
i
],
eventExpectV
[
i
+
1
:
]
...
)
close
(
msg
.
Ack
)
close
(
msg
.
Ack
)
// XXX -> send ack for all only when all collected?
continue
loop
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment