Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
7f2cfaff
Unverified
Commit
7f2cfaff
authored
Apr 14, 2020
by
Petar Radovic
Committed by
GitHub
Apr 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests time improvement (#90)
* improve execution time of tests
parent
bc67a6bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
18 deletions
+33
-18
hive_test.go
pkg/hive/hive_test.go
+2
-2
libp2p_test.go
pkg/p2p/libp2p/libp2p_test.go
+1
-1
protobuf_test.go
pkg/p2p/protobuf/protobuf_test.go
+30
-15
No files found.
pkg/hive/hive_test.go
View file @
7f2cfaff
...
@@ -167,7 +167,7 @@ func TestBroadcastPeers(t *testing.T) {
...
@@ -167,7 +167,7 @@ func TestBroadcastPeers(t *testing.T) {
}
}
func
expectOverlaysEventually
(
t
*
testing
.
T
,
exporter
AddressExporter
,
wantOverlays
[]
swarm
.
Address
)
{
func
expectOverlaysEventually
(
t
*
testing
.
T
,
exporter
AddressExporter
,
wantOverlays
[]
swarm
.
Address
)
{
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
0
;
i
++
{
var
stringOverlays
[]
string
var
stringOverlays
[]
string
var
stringWantOverlays
[]
string
var
stringWantOverlays
[]
string
o
,
err
:=
exporter
.
Overlays
()
o
,
err
:=
exporter
.
Overlays
()
...
@@ -188,7 +188,7 @@ func expectOverlaysEventually(t *testing.T, exporter AddressExporter, wantOverla
...
@@ -188,7 +188,7 @@ func expectOverlaysEventually(t *testing.T, exporter AddressExporter, wantOverla
return
return
}
}
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
time
.
Sleep
(
1
0
*
time
.
Millisecond
)
}
}
o
,
err
:=
exporter
.
Overlays
()
o
,
err
:=
exporter
.
Overlays
()
...
...
pkg/p2p/libp2p/libp2p_test.go
View file @
7f2cfaff
...
@@ -104,7 +104,7 @@ func expectPeersEventually(t *testing.T, s *libp2p.Service, addrs ...swarm.Addre
...
@@ -104,7 +104,7 @@ func expectPeersEventually(t *testing.T, s *libp2p.Service, addrs ...swarm.Addre
if
len
(
peers
)
==
len
(
addrs
)
{
if
len
(
peers
)
==
len
(
addrs
)
{
break
break
}
}
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
time
.
Sleep
(
1
0
*
time
.
Millisecond
)
}
}
if
len
(
peers
)
!=
len
(
addrs
)
{
if
len
(
peers
)
!=
len
(
addrs
)
{
...
...
pkg/p2p/protobuf/protobuf_test.go
View file @
7f2cfaff
...
@@ -75,7 +75,7 @@ func TestReader_timeout(t *testing.T) {
...
@@ -75,7 +75,7 @@ func TestReader_timeout(t *testing.T) {
{
{
name
:
"NewReader"
,
name
:
"NewReader"
,
readerFunc
:
func
()
protobuf
.
Reader
{
readerFunc
:
func
()
protobuf
.
Reader
{
return
protobuf
.
NewReader
(
newMessageReader
(
messages
,
4
00
*
time
.
Millisecond
))
return
protobuf
.
NewReader
(
newMessageReader
(
messages
,
1
00
*
time
.
Millisecond
))
},
},
},
},
{
{
...
@@ -83,7 +83,7 @@ func TestReader_timeout(t *testing.T) {
...
@@ -83,7 +83,7 @@ func TestReader_timeout(t *testing.T) {
readerFunc
:
func
()
protobuf
.
Reader
{
readerFunc
:
func
()
protobuf
.
Reader
{
_
,
r
:=
protobuf
.
NewWriterAndReader
(
_
,
r
:=
protobuf
.
NewWriterAndReader
(
newNoopWriteCloser
(
newNoopWriteCloser
(
newMessageReader
(
messages
,
4
00
*
time
.
Millisecond
),
newMessageReader
(
messages
,
1
00
*
time
.
Millisecond
),
),
),
)
)
return
r
return
r
...
@@ -99,7 +99,7 @@ func TestReader_timeout(t *testing.T) {
...
@@ -99,7 +99,7 @@ func TestReader_timeout(t *testing.T) {
if
i
==
0
{
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
timeout
=
600
*
time
.
Millisecond
}
else
{
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
defer
cancel
()
...
@@ -129,7 +129,7 @@ func TestReader_timeout(t *testing.T) {
...
@@ -129,7 +129,7 @@ func TestReader_timeout(t *testing.T) {
if
i
==
0
{
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
timeout
=
600
*
time
.
Millisecond
}
else
{
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
}
err
:=
r
.
ReadMsgWithTimeout
(
timeout
,
&
msg
)
err
:=
r
.
ReadMsgWithTimeout
(
timeout
,
&
msg
)
if
i
==
0
{
if
i
==
0
{
...
@@ -204,14 +204,14 @@ func TestWriter_timeout(t *testing.T) {
...
@@ -204,14 +204,14 @@ func TestWriter_timeout(t *testing.T) {
{
{
name
:
"NewWriter"
,
name
:
"NewWriter"
,
writerFunc
:
func
()
(
protobuf
.
Writer
,
<-
chan
string
)
{
writerFunc
:
func
()
(
protobuf
.
Writer
,
<-
chan
string
)
{
w
,
msgs
:=
newMessageWriter
(
4
00
*
time
.
Millisecond
)
w
,
msgs
:=
newMessageWriter
(
1
00
*
time
.
Millisecond
)
return
protobuf
.
NewWriter
(
w
),
msgs
return
protobuf
.
NewWriter
(
w
),
msgs
},
},
},
},
{
{
name
:
"NewWriterAndReader"
,
name
:
"NewWriterAndReader"
,
writerFunc
:
func
()
(
protobuf
.
Writer
,
<-
chan
string
)
{
writerFunc
:
func
()
(
protobuf
.
Writer
,
<-
chan
string
)
{
w
,
msgs
:=
newMessageWriter
(
4
00
*
time
.
Millisecond
)
w
,
msgs
:=
newMessageWriter
(
1
00
*
time
.
Millisecond
)
writer
,
_
:=
protobuf
.
NewWriterAndReader
(
newNoopReadCloser
(
w
))
writer
,
_
:=
protobuf
.
NewWriterAndReader
(
newNoopReadCloser
(
w
))
return
writer
,
msgs
return
writer
,
msgs
},
},
...
@@ -226,7 +226,7 @@ func TestWriter_timeout(t *testing.T) {
...
@@ -226,7 +226,7 @@ func TestWriter_timeout(t *testing.T) {
if
i
==
0
{
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
timeout
=
600
*
time
.
Millisecond
}
else
{
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
defer
cancel
()
...
@@ -256,7 +256,7 @@ func TestWriter_timeout(t *testing.T) {
...
@@ -256,7 +256,7 @@ func TestWriter_timeout(t *testing.T) {
if
i
==
0
{
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
timeout
=
600
*
time
.
Millisecond
}
else
{
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
}
err
:=
w
.
WriteMsgWithTimeout
(
timeout
,
&
pb
.
Message
{
err
:=
w
.
WriteMsgWithTimeout
(
timeout
,
&
pb
.
Message
{
Text
:
m
,
Text
:
m
,
...
@@ -302,12 +302,10 @@ func TestReadMessages(t *testing.T) {
...
@@ -302,12 +302,10 @@ func TestReadMessages(t *testing.T) {
func
newMessageReader
(
messages
[]
string
,
delay
time
.
Duration
)
io
.
Reader
{
func
newMessageReader
(
messages
[]
string
,
delay
time
.
Duration
)
io
.
Reader
{
r
,
pipe
:=
io
.
Pipe
()
r
,
pipe
:=
io
.
Pipe
()
w
:=
protobuf
.
NewWriter
(
pipe
)
w
:=
protobuf
.
NewWriter
(
pipe
)
go
func
()
{
go
func
()
{
for
_
,
m
:=
range
messages
{
for
_
,
m
:=
range
messages
{
time
.
Sleep
(
delay
)
if
err
:=
w
.
WriteMsg
(
&
pb
.
Message
{
if
err
:=
w
.
WriteMsg
(
&
pb
.
Message
{
Text
:
m
,
Text
:
m
,
});
err
!=
nil
{
});
err
!=
nil
{
...
@@ -319,14 +317,12 @@ func newMessageReader(messages []string, delay time.Duration) io.Reader {
...
@@ -319,14 +317,12 @@ func newMessageReader(messages []string, delay time.Duration) io.Reader {
}
}
}()
}()
return
r
return
delayedReader
{
r
:
r
,
delay
:
delay
}
}
}
func
newMessageWriter
(
delay
time
.
Duration
)
(
w
io
.
Writer
,
messages
<-
chan
string
)
{
func
newMessageWriter
(
delay
time
.
Duration
)
(
w
io
.
Writer
,
messages
<-
chan
string
)
{
pipe
,
w
:=
io
.
Pipe
()
pipe
,
w
:=
io
.
Pipe
()
r
:=
protobuf
.
NewReader
(
pipe
)
r
:=
protobuf
.
NewReader
(
pipe
)
msgs
:=
make
(
chan
string
)
msgs
:=
make
(
chan
string
)
go
func
()
{
go
func
()
{
...
@@ -334,7 +330,6 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
...
@@ -334,7 +330,6 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
var
msg
pb
.
Message
var
msg
pb
.
Message
for
{
for
{
time
.
Sleep
(
delay
)
err
:=
r
.
ReadMsg
(
&
msg
)
err
:=
r
.
ReadMsg
(
&
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
...
@@ -345,7 +340,27 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
...
@@ -345,7 +340,27 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
msgs
<-
msg
.
Text
msgs
<-
msg
.
Text
}
}
}()
}()
return
w
,
msgs
return
delayedWriter
{
w
:
w
,
delay
:
delay
},
msgs
}
type
delayedWriter
struct
{
w
io
.
Writer
delay
time
.
Duration
}
func
(
d
delayedWriter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
time
.
Sleep
(
d
.
delay
)
return
d
.
w
.
Write
(
p
)
}
type
delayedReader
struct
{
r
io
.
Reader
delay
time
.
Duration
}
func
(
d
delayedReader
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
time
.
Sleep
(
d
.
delay
)
return
d
.
r
.
Read
(
p
)
}
}
type
noopWriteCloser
struct
{
type
noopWriteCloser
struct
{
...
...
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