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
Hide 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) {
}
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
stringWantOverlays
[]
string
o
,
err
:=
exporter
.
Overlays
()
...
...
@@ -188,7 +188,7 @@ func expectOverlaysEventually(t *testing.T, exporter AddressExporter, wantOverla
return
}
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
time
.
Sleep
(
1
0
*
time
.
Millisecond
)
}
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
if
len
(
peers
)
==
len
(
addrs
)
{
break
}
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
time
.
Sleep
(
1
0
*
time
.
Millisecond
)
}
if
len
(
peers
)
!=
len
(
addrs
)
{
...
...
pkg/p2p/protobuf/protobuf_test.go
View file @
7f2cfaff
...
...
@@ -75,7 +75,7 @@ func TestReader_timeout(t *testing.T) {
{
name
:
"NewReader"
,
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) {
readerFunc
:
func
()
protobuf
.
Reader
{
_
,
r
:=
protobuf
.
NewWriterAndReader
(
newNoopWriteCloser
(
newMessageReader
(
messages
,
4
00
*
time
.
Millisecond
),
newMessageReader
(
messages
,
1
00
*
time
.
Millisecond
),
),
)
return
r
...
...
@@ -99,7 +99,7 @@ func TestReader_timeout(t *testing.T) {
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
...
...
@@ -129,7 +129,7 @@ func TestReader_timeout(t *testing.T) {
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
err
:=
r
.
ReadMsgWithTimeout
(
timeout
,
&
msg
)
if
i
==
0
{
...
...
@@ -204,14 +204,14 @@ func TestWriter_timeout(t *testing.T) {
{
name
:
"NewWriter"
,
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
},
},
{
name
:
"NewWriterAndReader"
,
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
))
return
writer
,
msgs
},
...
...
@@ -226,7 +226,7 @@ func TestWriter_timeout(t *testing.T) {
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
...
...
@@ -256,7 +256,7 @@ func TestWriter_timeout(t *testing.T) {
if
i
==
0
{
timeout
=
600
*
time
.
Millisecond
}
else
{
timeout
=
20
0
*
time
.
Millisecond
timeout
=
1
0
*
time
.
Millisecond
}
err
:=
w
.
WriteMsgWithTimeout
(
timeout
,
&
pb
.
Message
{
Text
:
m
,
...
...
@@ -302,12 +302,10 @@ func TestReadMessages(t *testing.T) {
func
newMessageReader
(
messages
[]
string
,
delay
time
.
Duration
)
io
.
Reader
{
r
,
pipe
:=
io
.
Pipe
()
w
:=
protobuf
.
NewWriter
(
pipe
)
go
func
()
{
for
_
,
m
:=
range
messages
{
time
.
Sleep
(
delay
)
if
err
:=
w
.
WriteMsg
(
&
pb
.
Message
{
Text
:
m
,
});
err
!=
nil
{
...
...
@@ -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
)
{
pipe
,
w
:=
io
.
Pipe
()
r
:=
protobuf
.
NewReader
(
pipe
)
msgs
:=
make
(
chan
string
)
go
func
()
{
...
...
@@ -334,7 +330,6 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
var
msg
pb
.
Message
for
{
time
.
Sleep
(
delay
)
err
:=
r
.
ReadMsg
(
&
msg
)
if
err
!=
nil
{
if
err
==
io
.
EOF
{
...
...
@@ -345,7 +340,27 @@ func newMessageWriter(delay time.Duration) (w io.Writer, messages <-chan string)
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
{
...
...
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