Skip to content

Commit 1695216

Browse files
committed
Add ping example
Closes #227
1 parent de8e29b commit 1695216

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

autobahn_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ var autobahnCases = []string{"*"}
3636
func TestAutobahn(t *testing.T) {
3737
t.Parallel()
3838

39-
if os.Getenv("AUTOBAHN_TEST") == "" {
39+
if os.Getenv("AUTOBAHN") == "" {
4040
t.SkipNow()
4141
}
4242

43-
if os.Getenv("AUTOBAHN_FAST") != "" {
43+
if os.Getenv("AUTOBAHN") == "fast" {
44+
// These are the slow tests.
4445
excludedAutobahnCases = append(excludedAutobahnCases,
4546
"9.*", "13.*", "12.*",
4647
)

example_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ func Example_crossOrigin() {
135135
log.Fatal(err)
136136
}
137137

138+
func ExampleConn_Ping() {
139+
// Dials a server and pings it 5 times.
140+
141+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
142+
defer cancel()
143+
144+
c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
145+
if err != nil {
146+
log.Fatal(err)
147+
}
148+
defer c.Close(websocket.StatusInternalError, "the sky is falling")
149+
150+
// Required to read the Pongs from the server.
151+
ctx = c.CloseRead(ctx)
152+
153+
for i := 0; i < 5; i++ {
154+
err = c.Ping(ctx)
155+
if err != nil {
156+
log.Fatal(err)
157+
}
158+
}
159+
160+
c.Close(websocket.StatusNormalClosure, "")
161+
}
162+
138163
// This example demonstrates how to create a WebSocket server
139164
// that gracefully exits when sent a signal.
140165
//

0 commit comments

Comments
 (0)