Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-msgio
Commits
47494676
Commit
47494676
authored
Dec 11, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for close when reading/writing
parent
f772aae9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
1 deletion
+42
-1
msgio_test.go
msgio_test.go
+42
-1
No files found.
msgio_test.go
View file @
47494676
...
...
@@ -3,12 +3,13 @@ package msgio
import
(
"bytes"
"fmt"
randbuf
"github.com/jbenet/go-randbuf"
"io"
"math/rand"
"sync"
"testing"
"time"
randbuf
"github.com/jbenet/go-randbuf"
)
func
TestReadWrite
(
t
*
testing
.
T
)
{
...
...
@@ -195,3 +196,43 @@ func TestBadSizes(t *testing.T) {
}
_
=
msg
}
func
TestReadClose
(
t
*
testing
.
T
)
{
r
,
w
:=
io
.
Pipe
()
writer
:=
NewWriter
(
w
)
defer
writer
.
Close
()
reader
:=
NewReader
(
r
)
buf
:=
[
10
]
byte
{}
done
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
done
)
time
.
Sleep
(
10
*
time
.
Millisecond
)
reader
.
Close
()
}()
n
,
err
:=
reader
.
Read
(
buf
[
:
])
if
n
!=
0
||
err
==
nil
{
t
.
Error
(
"expected to read nothing"
)
}
<-
done
}
func
TestWriteClose
(
t
*
testing
.
T
)
{
r
,
w
:=
io
.
Pipe
()
writer
:=
NewWriter
(
w
)
reader
:=
NewReader
(
r
)
defer
reader
.
Close
()
buf
:=
[
10
]
byte
{}
done
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
done
)
time
.
Sleep
(
10
*
time
.
Millisecond
)
writer
.
Close
()
}()
n
,
err
:=
writer
.
Write
(
buf
[
:
])
if
n
!=
0
||
err
==
nil
{
t
.
Error
(
"expected to read nothing"
)
}
<-
done
}
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