Skip to content

Commit

Permalink
Fixed deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AsafMah committed Dec 3, 2023
1 parent e0bd69f commit b456b2d
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions azkustodata/query/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func TestReadFramesWithValidInput(t *testing.T) {
t.Parallel()
ch := make(chan Frame)

var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(validFrames), ch)
require.NoError(t, err)
err := ReadFrames(strings.NewReader(validFrames), ch)
errChan <- err
}()

dataSetHeader := <-ch
Expand Down Expand Up @@ -95,17 +96,20 @@ func TestReadFramesWithValidInput(t *testing.T) {

assert.Nil(t, <-ch)

err := <-errChan
require.NoError(t, err)
}

func TestReadFramesWithErrors(t *testing.T) {
t.Parallel()
ch := make(chan Frame)

var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(errorFrames), ch)
err := ReadFrames(strings.NewReader(errorFrames), ch)
errChan <- err
require.NoError(t, err)
}()

Expand Down Expand Up @@ -206,6 +210,7 @@ func TestReadFramesWithErrors(t *testing.T) {

assert.Nil(t, <-ch)

err := <-errChan
require.NoError(t, err)
}

Expand All @@ -214,16 +219,19 @@ func TestReadFramesWithEmptyInput(t *testing.T) {
src := ``

ch := make(chan Frame)
var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(src), ch)
err := ReadFrames(strings.NewReader(src), ch)
errChan <- err
}()

for range ch {
assert.Fail(t, "should not receive any frames")
}

err := <-errChan
require.NoError(t, err)
}

Expand All @@ -232,16 +240,19 @@ func TestReadFramesWithInvalidInput(t *testing.T) {
src := `[{]`

ch := make(chan Frame)
var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(src), ch)
err := ReadFrames(strings.NewReader(src), ch)
errChan <- err
}()

for range ch {
assert.Fail(t, "should not receive any frames")
}

err := <-errChan
require.ErrorContains(t, err, "invalid character ']'")
}

Expand All @@ -251,15 +262,18 @@ func TestReadFramesWithInvalidFrameType(t *testing.T) {
]`

ch := make(chan Frame)
var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(src), ch)
err := ReadFrames(strings.NewReader(src), ch)
errChan <- err
}()

invalid := <-ch
assert.Nil(t, invalid)

err := <-errChan
require.ErrorContains(t, err, "unknown frame type: InvalidFrameType")
}

Expand All @@ -269,14 +283,17 @@ func TestReadFramesWithInvalidFrame(t *testing.T) {
]`

ch := make(chan Frame)
var err error
// err channel
errChan := make(chan error)

go func() {
err = ReadFrames(strings.NewReader(src), ch)
err := ReadFrames(strings.NewReader(src), ch)
errChan <- err
}()

invalid := <-ch
assert.Nil(t, invalid)

err := <-errChan
require.ErrorContains(t, err, "json: cannot unmarshal string")
}

0 comments on commit b456b2d

Please sign in to comment.