Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5445abf

Browse files
committed
Add wspb test
1 parent2f11da9 commit5445abf

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

‎conn_test.go‎

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ import (
1515
"testing"
1616
"time"
1717

18+
"github.com/golang/protobuf/proto"
19+
"github.com/golang/protobuf/ptypes"
20+
"github.com/golang/protobuf/ptypes/duration"
1821
"golang.org/x/xerrors"
1922

2023
"nhooyr.io/websocket"
2124
"nhooyr.io/websocket/internal/test/cmp"
2225
"nhooyr.io/websocket/internal/test/wstest"
2326
"nhooyr.io/websocket/internal/test/xrand"
2427
"nhooyr.io/websocket/internal/xsync"
28+
"nhooyr.io/websocket/wsjson"
29+
"nhooyr.io/websocket/wspb"
2530
)
2631

2732
funcTestConn(t*testing.T) {
2833
t.Parallel()
2934

30-
t.Run("data",func(t*testing.T) {
35+
t.Run("fuzzData",func(t*testing.T) {
3136
t.Parallel()
3237

3338
fori:=0;i<5;i++ {
@@ -317,6 +322,102 @@ func TestConn(t *testing.T) {
317322
t.Fatal(err)
318323
}
319324
})
325+
326+
t.Run("wsjson",func(t*testing.T) {
327+
t.Parallel()
328+
329+
c1,c2,err:=wstest.Pipe(nil,nil)
330+
iferr!=nil {
331+
t.Fatal(err)
332+
}
333+
deferc2.Close(websocket.StatusInternalError,"")
334+
deferc1.Close(websocket.StatusInternalError,"")
335+
336+
ctx,cancel:=context.WithTimeout(context.Background(),time.Second*5)
337+
defercancel()
338+
339+
echoLoopErr:=xsync.Go(func()error {
340+
err:=wstest.EchoLoop(ctx,c2)
341+
returnassertCloseStatus(websocket.StatusNormalClosure,err)
342+
})
343+
deferfunc() {
344+
err:=<-echoLoopErr
345+
iferr!=nil {
346+
t.Errorf("echo loop error: %v",err)
347+
}
348+
}()
349+
defercancel()
350+
351+
c1.SetReadLimit(131072)
352+
353+
exp:=xrand.String(xrand.Int(131072))
354+
err=wsjson.Write(ctx,c1,exp)
355+
iferr!=nil {
356+
t.Fatal(err)
357+
}
358+
359+
varactinterface{}
360+
err=wsjson.Read(ctx,c1,&act)
361+
iferr!=nil {
362+
t.Fatal(err)
363+
}
364+
ifexp!=act {
365+
t.Fatal(cmp.Diff(exp,act))
366+
}
367+
368+
err=c1.Close(websocket.StatusNormalClosure,"")
369+
iferr!=nil {
370+
t.Fatalf("unexpected error: %v",err)
371+
}
372+
})
373+
374+
t.Run("wspb",func(t*testing.T) {
375+
t.Parallel()
376+
377+
c1,c2,err:=wstest.Pipe(nil,nil)
378+
iferr!=nil {
379+
t.Fatal(err)
380+
}
381+
deferc2.Close(websocket.StatusInternalError,"")
382+
deferc1.Close(websocket.StatusInternalError,"")
383+
384+
ctx,cancel:=context.WithTimeout(context.Background(),time.Second*5)
385+
defercancel()
386+
387+
echoLoopErr:=xsync.Go(func()error {
388+
err:=wstest.EchoLoop(ctx,c2)
389+
returnassertCloseStatus(websocket.StatusNormalClosure,err)
390+
})
391+
deferfunc() {
392+
err:=<-echoLoopErr
393+
iferr!=nil {
394+
t.Errorf("echo loop error: %v",err)
395+
}
396+
}()
397+
defercancel()
398+
399+
c1.SetReadLimit(131072)
400+
401+
exp:=ptypes.DurationProto(100)
402+
err=wspb.Write(ctx,c1,exp)
403+
iferr!=nil {
404+
t.Fatal(err)
405+
}
406+
407+
act:=&duration.Duration{}
408+
err=wspb.Read(ctx,c1,act)
409+
iferr!=nil {
410+
t.Fatal(err)
411+
}
412+
if!proto.Equal(exp,act) {
413+
t.Fatal(cmp.Diff(exp,act))
414+
}
415+
416+
err=c1.Close(websocket.StatusNormalClosure,"")
417+
iferr!=nil {
418+
t.Fatalf("unexpected error: %v",err)
419+
}
420+
})
320421
}
321422

322423
funcTestWasm(t*testing.T) {
@@ -345,7 +446,7 @@ func TestWasm(t *testing.T) {
345446
deferwg.Wait()
346447
defers.Close()
347448

348-
ctx,cancel:=context.WithTimeout(context.Background(),time.Second*20)
449+
ctx,cancel:=context.WithTimeout(context.Background(),time.Minute)
349450
defercancel()
350451

351452
cmd:=exec.CommandContext(ctx,"go","test","-exec=wasmbrowsertest","./...")

‎ws_js_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
funcTestWasm(t*testing.T) {
1616
t.Parallel()
1717

18-
ctx,cancel:=context.WithTimeout(context.Background(),time.Second*20)
18+
ctx,cancel:=context.WithTimeout(context.Background(),time.Minute)
1919
defercancel()
2020

2121
c,resp,err:=websocket.Dial(ctx,os.Getenv("WS_ECHO_SERVER_URL"),&websocket.DialOptions{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp