-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make it possible to wait for a query lambda
- Loading branch information
Showing
16 changed files
with
336 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var ErrBadWaitState = errors.New("encountered bad state while waiting for resource") | ||
|
||
type BadWaitState struct { | ||
State string | ||
} | ||
|
||
func (e BadWaitState) Error() string { | ||
return fmt.Sprintf("%s: %s", ErrBadWaitState.Error(), e.State) | ||
} | ||
func (e BadWaitState) Unwrap() error { | ||
return ErrBadWaitState | ||
} | ||
|
||
func NewBadWaitStateError(state string) BadWaitState { | ||
return BadWaitState{ | ||
State: state, | ||
} | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
package wait | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rockset/rockset-go-client/option" | ||
) | ||
|
||
// UntilQueryLambdaVersionGone waits until a query lambda is deleted, i.e. GetQueryLambda() returns "not found". | ||
func (w *Waiter) UntilQueryLambdaVersionGone(ctx context.Context, workspace, name, version string) error { | ||
return w.rc.RetryWithCheck(ctx, ResourceIsGone(ctx, func(ctx context.Context) error { | ||
_, err := w.rc.GetQueryLambdaVersion(ctx, workspace, name, version) | ||
return err | ||
})) | ||
} | ||
|
||
// UntilQueryLambdaVersionActive waits until the Virtual Instance is active. | ||
func (w *Waiter) UntilQueryLambdaVersionActive(ctx context.Context, workspace, name, version string) error { | ||
return w.rc.RetryWithCheck(ctx, | ||
ResourceHasState(ctx, []option.QueryLambdaState{option.QueryLambdaActive}, []option.QueryLambdaState{option.QueryLambdaInvalid}, | ||
func(ctx context.Context) (option.QueryLambdaState, error) { | ||
ql, err := w.rc.GetQueryLambdaVersion(ctx, workspace, name, version) | ||
return option.QueryLambdaState(ql.GetState()), err | ||
})) | ||
} |
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,36 @@ | ||
package wait_test | ||
|
||
import ( | ||
"context" | ||
rockerr "github.com/rockset/rockset-go-client/errors" | ||
"testing" | ||
|
||
"github.com/rockset/rockset-go-client/openapi" | ||
"github.com/rockset/rockset-go-client/option" | ||
"github.com/rockset/rockset-go-client/wait" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWait_untilQueryLambdaActive(t *testing.T) { | ||
ctx := context.TODO() | ||
|
||
rs := fakeRocksetClient() | ||
rs.GetQueryLambdaVersionReturnsOnCall(0, openapi.QueryLambdaVersion{State: openapi.PtrString("")}, nil) | ||
rs.GetQueryLambdaVersionReturnsOnCall(1, openapi.QueryLambdaVersion{State: openapi.PtrString(option.QueryLambdaActive.String())}, nil) | ||
|
||
err := wait.New(&rs).UntilQueryLambdaVersionActive(ctx, "ws", "ql", "v") | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, rs.GetQueryLambdaVersionCallCount()) | ||
} | ||
|
||
func TestWait_untilQueryLambdaActive_invalid(t *testing.T) { | ||
ctx := context.TODO() | ||
|
||
rs := fakeRocksetClient() | ||
rs.GetQueryLambdaVersionReturnsOnCall(0, openapi.QueryLambdaVersion{State: openapi.PtrString("")}, nil) | ||
rs.GetQueryLambdaVersionReturnsOnCall(1, openapi.QueryLambdaVersion{State: openapi.PtrString(option.QueryLambdaInvalid.String())}, nil) | ||
|
||
err := wait.New(&rs).UntilQueryLambdaVersionActive(ctx, "ws", "ql", "v") | ||
assert.ErrorIs(t, err, rockerr.ErrBadWaitState) | ||
assert.Equal(t, 2, rs.GetQueryLambdaVersionCallCount()) | ||
} |
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,24 @@ | ||
package wait_test | ||
|
||
import ( | ||
"context" | ||
"github.com/rockset/rockset-go-client/option" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/rockset/rockset-go-client/openapi" | ||
"github.com/rockset/rockset-go-client/wait" | ||
) | ||
|
||
func TestWait_untilQueryDone(t *testing.T) { | ||
ctx := context.TODO() | ||
|
||
rs := fakeRocksetClient() | ||
rs.GetQueryInfoReturnsOnCall(0, openapi.QueryInfo{Status: openapi.PtrString(option.QueryRunning.String())}, nil) | ||
rs.GetQueryInfoReturnsOnCall(1, openapi.QueryInfo{Status: openapi.PtrString(option.QueryCompleted.String())}, nil) | ||
|
||
err := wait.New(&rs).UntilQueryDone(ctx, "id") | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, rs.GetQueryInfoCallCount()) | ||
} |
Oops, something went wrong.