-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix multi-goroutine request error (#54)
* fix multi-goroutine bug and add multi-goroutine request test 1. panic: concurrent write to websocket connection 2. request GetSceneList: mismatched ID: expected response with ID c30f63f4-0065-4cb0-5873-19e12a676ee1, but got 97362273-a871-415b-6610-45894239012e * generate goroutine test * these tests actually don't have to be generated put them in a separate file * add goroutine test --------- Co-authored-by: Andrey Kaipov <andreykaipov@users.noreply.github.com>
- Loading branch information
1 parent
ae9a1ff
commit ec56dc7
Showing
5 changed files
with
76 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package goobs_test | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"os" | ||
"sync" | ||
"testing" | ||
|
||
goobs "github.com/andreykaipov/goobs" | ||
"github.com/gorilla/websocket" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_client(t *testing.T) { | ||
var err error | ||
_, err = goobs.New( | ||
"localhost:"+os.Getenv("OBS_PORT"), | ||
goobs.WithPassword("wrongpassword"), | ||
goobs.WithRequestHeader(http.Header{"User-Agent": []string{"goobs-e2e/0.0.0"}}), | ||
) | ||
assert.Error(t, err) | ||
assert.IsType(t, &websocket.CloseError{}, err) | ||
assert.Equal(t, err.(*websocket.CloseError).Code, 4009) | ||
_, err = goobs.New( | ||
"localhost:42069", | ||
goobs.WithPassword("wrongpassword"), | ||
goobs.WithRequestHeader(http.Header{"User-Agent": []string{"goobs-e2e/0.0.0"}}), | ||
) | ||
assert.Error(t, err) | ||
assert.IsType(t, &net.OpError{}, err) | ||
} | ||
|
||
func Test_multi_goroutine(t *testing.T) { | ||
client, err := goobs.New( | ||
"localhost:"+os.Getenv("OBS_PORT"), | ||
goobs.WithPassword("goodpassword"), | ||
goobs.WithRequestHeader(http.Header{"User-Agent": []string{"goobs-e2e/0.0.0"}}), | ||
) | ||
assert.NoError(t, err) | ||
t.Cleanup(func() { | ||
client.Disconnect() | ||
}) | ||
wg := sync.WaitGroup{} | ||
for i := 0; i < 1000; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
_, err := client.Scenes.GetSceneList() | ||
assert.NoError(t, err) | ||
}() | ||
} | ||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters