-
Notifications
You must be signed in to change notification settings - Fork 154
Add acceptance test for bundle run
#2695
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
Changes from all commits
31b7ad0
bf234c4
42f6ecf
4f43fb9
90c6ad0
6002e0d
1b5ff48
c442378
152d982
f0d1dc5
080d1bf
58d28a9
9939562
05cd18c
a2748d5
898b2c1
1996d3f
88b6dc8
fd2600c
93c5e3f
bbbbf30
eb58d11
007a714
0c9fbf7
edf7051
769acf7
4061036
c0d34f7
112a9de
647dab0
be3be9c
150a51c
39d0b13
2212aa2
7fb464b
b5e2123
39ec48a
2c77368
4ef33dc
996b58a
fcc2966
09c05db
acff901
de5a348
7dc24b6
90a9584
8c094db
5586121
26684b1
8e19474
d9b5f5e
987220b
2ba81e3
98f33a8
9ea6144
3c4ff15
2866956
6239f4b
28ea87e
a6d161a
a7ffe5d
c56f6f5
a0fcc5d
f30dffa
7d46902
c0c1ac6
3b57925
e5e6ea4
b0bb768
fa6151b
b515f2d
396fc21
8add0f8
8056fd2
a6f0694
fd43bd7
fd2f755
ff71a22
576a16e
1f36d74
4c327f5
2a06b49
72305f1
92bf456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| bundle: | ||
| name: caterpillar | ||
|
|
||
|
|
||
| resources: | ||
| jobs: | ||
| foo: | ||
| name: foo | ||
| tasks: | ||
| - task_key: task | ||
| spark_python_task: | ||
| python_file: ./foo.py | ||
| environment_key: default | ||
|
|
||
| environments: | ||
| - environment_key: default | ||
| spec: | ||
| client: "2" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| print(1) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
|
|
||
| === no run key specified | ||
| >>> [CLI] bundle run | ||
| Error: expected a KEY of the resource to run | ||
|
|
||
| Exit code: 1 | ||
|
|
||
| === deploy and run resource | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/caterpillar/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] bundle run foo | ||
| Run URL: [DATABRICKS_URL]/job/run/1 | ||
|
|
||
| [DATE] HH:MM:SS "run-name" TERMINATED | ||
|
|
||
| === no resource key with -- | ||
| >>> [CLI] bundle run -- | ||
| Error: expected a KEY of the resource to run | ||
|
|
||
| Exit code: 1 | ||
|
|
||
| === resource key with parameters | ||
| >>> [CLI] bundle run foo -- arg1 arg2 | ||
| Run URL: [DATABRICKS_URL]/job/run/2 | ||
|
|
||
| [DATE] HH:MM:SS "run-name" TERMINATED | ||
|
|
||
| === inline script | ||
| >>> [CLI] bundle run -- echo hello | ||
| hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| title "no run key specified" | ||
| errcode trace $CLI bundle run | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: personally prefer smaller tests, easier to review/debug and faster to run. e.g. you could split error-raising commands from the rest. if you have one command then you also don't need to specify title (it's test name), errcode and trace.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, but in this case it's only 5 commands so still small. The flip side is you end up with a bunch of really granular files / tests which does not seem optimal. |
||
|
|
||
| title "deploy and run resource" | ||
| errcode trace $CLI bundle deploy | ||
|
|
||
| errcode trace $CLI bundle run foo | ||
|
|
||
| title "no resource key with --" | ||
| errcode trace $CLI bundle run -- | ||
|
|
||
| title "resource key with parameters" | ||
| errcode trace $CLI bundle run foo -- arg1 arg2 | ||
|
|
||
| title "inline script" | ||
| errcode trace $CLI bundle run -- echo "hello" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [[Repls]] | ||
| Old = "(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]" | ||
| New = "HH:MM:SS" | ||
|
|
||
| [[Repls]] | ||
| Old = '20\d\d-\d\d-\d\d' | ||
| New = '[DATE]' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,16 @@ import ( | |
|
|
||
| // FakeWorkspace holds a state of a workspace for acceptance tests. | ||
| type FakeWorkspace struct { | ||
| mu sync.Mutex | ||
| mu sync.Mutex | ||
| url string | ||
|
|
||
| directories map[string]bool | ||
| files map[string][]byte | ||
| // normally, ids are not sequential, but we make them sequential for deterministic diff | ||
| nextJobId int64 | ||
| jobs map[int64]jobs.Job | ||
| nextJobId int64 | ||
| nextJobRunId int64 | ||
| jobs map[int64]jobs.Job | ||
| jobRuns map[int64]jobs.Run | ||
|
|
||
| Pipelines map[string]pipelines.PipelineSpec | ||
| Monitors map[string]catalog.MonitorInfo | ||
|
|
@@ -70,19 +73,21 @@ func MapDelete[T any](w *FakeWorkspace, collection map[string]T, key string) Res | |
| return Response{} | ||
| } | ||
|
|
||
| func NewFakeWorkspace() *FakeWorkspace { | ||
| func NewFakeWorkspace(url string) *FakeWorkspace { | ||
| return &FakeWorkspace{ | ||
| url: url, | ||
| directories: map[string]bool{ | ||
| "/Workspace": true, | ||
| }, | ||
| files: map[string][]byte{}, | ||
| jobs: map[int64]jobs.Job{}, | ||
| nextJobId: 1, | ||
|
|
||
| Pipelines: map[string]pipelines.PipelineSpec{}, | ||
| Monitors: map[string]catalog.MonitorInfo{}, | ||
| Apps: map[string]apps.App{}, | ||
| Schemas: map[string]catalog.SchemaInfo{}, | ||
| files: map[string][]byte{}, | ||
| jobs: map[int64]jobs.Job{}, | ||
| jobRuns: map[int64]jobs.Run{}, | ||
| nextJobId: 1, | ||
| nextJobRunId: 1, | ||
| Pipelines: map[string]pipelines.PipelineSpec{}, | ||
| Monitors: map[string]catalog.MonitorInfo{}, | ||
| Apps: map[string]apps.App{}, | ||
| Schemas: map[string]catalog.SchemaInfo{}, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -247,6 +252,52 @@ func (s *FakeWorkspace) JobsGet(jobId string) Response { | |
| } | ||
| } | ||
|
|
||
| func (s *FakeWorkspace) JobsRunNow(jobId int64) Response { | ||
| defer s.LockUnlock()() | ||
|
|
||
| _, ok := s.jobs[jobId] | ||
| if !ok { | ||
| return Response{ | ||
| StatusCode: 404, | ||
| } | ||
| } | ||
|
|
||
| runId := s.nextJobRunId | ||
| s.nextJobRunId++ | ||
| s.jobRuns[runId] = jobs.Run{ | ||
| RunId: runId, | ||
| State: &jobs.RunState{ | ||
| LifeCycleState: jobs.RunLifeCycleStateRunning, | ||
| }, | ||
| RunPageUrl: fmt.Sprintf("%s/job/run/%d", s.url, runId), | ||
| RunType: jobs.RunTypeJobRun, | ||
| RunName: "run-name", | ||
| } | ||
|
|
||
| return Response{ | ||
| Body: jobs.RunNowResponse{ | ||
| RunId: runId, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (s *FakeWorkspace) JobsGetRun(runId int64) Response { | ||
| defer s.LockUnlock()() | ||
|
|
||
| run, ok := s.jobRuns[runId] | ||
| if !ok { | ||
| return Response{ | ||
| StatusCode: 404, | ||
| } | ||
| } | ||
|
|
||
| // Mark the run as terminated. | ||
| run.State.LifeCycleState = jobs.RunLifeCycleStateTerminated | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be very specific to a particular test, might not be reusable. Perhaps instead you can have explicit endpoint to update this field?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bundle run command blocks for the run to terminate. The run state is an internal detail and all runs automatically transition to terminated, so it's a fair way to model this in a fake workspace.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, we can extend this later. |
||
| return Response{ | ||
| Body: run, | ||
| } | ||
| } | ||
|
|
||
| func (s *FakeWorkspace) PipelinesGet(pipelineId string) Response { | ||
| defer s.LockUnlock()() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it here? The last command is "echo" which includes a newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run command itself has a trailing space in it's output, not the echo command. Specifically:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this easily fixable? I would prefer to keep this ignore list to the absolute minimum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to fix in #2864