Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dst): correct error messages #120

Merged
merged 5 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions test/dst/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dst

import (
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -73,15 +74,17 @@ func (m *Model) addCursor(next *t_api.Request) {

func (m *Model) Step(req *t_api.Request, res *t_api.Response, err error) error {
if err != nil {
switch err.Error() {
case "api submission queue full":
return nil
case "subsystem:store:sqlite submission queue full":
var resErr *t_api.ResonateError
if !errors.As(err, &resErr) {
return fmt.Errorf("unexpected non-resonate error '%v'", err)
}
switch resErr.Code() {
case t_api.ErrAPISubmissionQueueFull:
return nil
case "subsystem:network:dst submission queue full":
case t_api.ErrAIOSubmissionQueueFull:
return nil
default:
return fmt.Errorf("unexpected error '%v'", err)
return fmt.Errorf("unexpected resonate error '%v'", resErr)
}
}

Expand Down
64 changes: 64 additions & 0 deletions test/dst/model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dst

import (
"errors"
"testing"

"github.com/resonatehq/resonate/internal/kernel/t_api"
"github.com/stretchr/testify/require"
)

func TestModelStep(t *testing.T) {
tcs := []struct {
name string
m *Model
req *t_api.Request
res *t_api.Response
err error
wantErr bool
}{
{
name: "api submission queue full error",
m: &Model{},
req: &t_api.Request{},
res: &t_api.Response{},
err: t_api.NewResonateError(t_api.ErrAPISubmissionQueueFull, "", nil),
wantErr: false,
},
{
name: "aio submission queue full error",
m: &Model{},
req: &t_api.Request{},
res: &t_api.Response{},
err: t_api.NewResonateError(t_api.ErrAIOSubmissionQueueFull, "", nil),
wantErr: false,
},
{
name: "unexpected resonate error",
m: &Model{},
req: &t_api.Request{},
res: &t_api.Response{},
err: t_api.NewResonateError(-1, "", nil),
wantErr: true,
},
{
name: "unexpected non-resonate error",
m: &Model{},
req: &t_api.Request{},
res: &t_api.Response{},
err: errors.New("unexpected non-resonate error"),
wantErr: true,
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
err := tc.m.Step(tc.req, tc.res, tc.err)
if tc.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}