Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
47b835e4
Commit
47b835e4
authored
Jul 14, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
channel tests: added a couple of tests with closed channels
R=rsc CC=golang-dev
https://golang.org/cl/1774047
parent
a3855235
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
select3.go
test/chan/select3.go
+33
-1
No files found.
test/chan/select3.go
View file @
47b835e4
...
@@ -25,7 +25,7 @@ func testPanic(signal string, f func()) {
...
@@ -25,7 +25,7 @@ func testPanic(signal string, f func()) {
defer
func
()
{
defer
func
()
{
s
:=
never
s
:=
never
if
recover
()
!=
nil
{
if
recover
()
!=
nil
{
s
=
always
// f panicked
s
=
always
// f panicked
}
}
if
s
!=
signal
{
if
s
!=
signal
{
panic
(
signal
+
" panic"
)
panic
(
signal
+
" panic"
)
...
@@ -55,6 +55,8 @@ func testBlock(signal string, f func()) {
...
@@ -55,6 +55,8 @@ func testBlock(signal string, f func()) {
func
main
()
{
func
main
()
{
const
async
=
1
// asynchronous channels
const
async
=
1
// asynchronous channels
var
nilch
chan
int
var
nilch
chan
int
closedch
:=
make
(
chan
int
)
close
(
closedch
)
// sending/receiving from a nil channel outside a select panics
// sending/receiving from a nil channel outside a select panics
testPanic
(
always
,
func
()
{
testPanic
(
always
,
func
()
{
...
@@ -86,6 +88,24 @@ func main() {
...
@@ -86,6 +88,24 @@ func main() {
ch
<-
7
ch
<-
7
})
})
// receiving (a small number of times) from a closed channel never blocks
testBlock
(
never
,
func
()
{
for
i
:=
0
;
i
<
10
;
i
++
{
if
<-
closedch
!=
0
{
panic
(
"expected zero value when reading from closed channel"
)
}
}
})
// sending (a small number of times) to a closed channel is not specified
// but the current implementation doesn't block: test that different
// implementations behave the same
testBlock
(
never
,
func
()
{
for
i
:=
0
;
i
<
10
;
i
++
{
closedch
<-
7
}
})
// receiving from a non-ready channel always blocks
// receiving from a non-ready channel always blocks
testBlock
(
always
,
func
()
{
testBlock
(
always
,
func
()
{
ch
:=
make
(
chan
int
)
ch
:=
make
(
chan
int
)
...
@@ -173,4 +193,16 @@ func main() {
...
@@ -173,4 +193,16 @@ func main() {
unreachable
()
unreachable
()
}
}
})
})
// selects with closed channels don't block
testBlock
(
never
,
func
()
{
select
{
case
<-
closedch
:
}
})
testBlock
(
never
,
func
()
{
select
{
case
closedch
<-
7
:
}
})
}
}
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