-
Notifications
You must be signed in to change notification settings - Fork 2
feat(runtime): expose precise SnapshotProgress during setup #97
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
Open
IOHelpMe
wants to merge
4
commits into
highcard-dev:master
Choose a base branch
from
IOHelpMe:marvin/hig-24-improve-fetching-scroll-progress-visibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cad3b6b
feat(runtime): expose scroll pull SnapshotProgress
IOHelpMe d8a8e13
fix(runtime): keep SnapshotProgress current during setup
IOHelpMe 3090388
fix(runtime): preserve SnapshotProgress tenths
IOHelpMe da0568d
fix(runtime): rely only on SnapshotProgress
IOHelpMe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,40 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/gofiber/fiber/v2" | ||
| appservices "github.com/highcard-dev/daemon/apps/druid/core/services" | ||
| ) | ||
|
|
||
| func TestRuntimeCallbackHandlerReportsProgress(t *testing.T) { | ||
| callbacks := appservices.NewWorkerCallbackManager() | ||
| token, _, err := callbacks.Register("runtime-1") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| handler := runtimeCallbackHandler{callbacks: callbacks} | ||
| app := fiber.New() | ||
| app.Post("/internal/v1/workers/:runtime_id/progress", handler.ReportProgress) | ||
|
|
||
| request := httptest.NewRequest( | ||
| http.MethodPost, | ||
| "/internal/v1/workers/runtime-1/progress", | ||
| strings.NewReader(fmt.Sprintf(`{"token":%q,"percentage":42}`, token)), | ||
| ) | ||
| request.Header.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON) | ||
| response, err := app.Test(request) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if response.StatusCode != http.StatusNoContent { | ||
| t.Fatalf("status = %d; want %d", response.StatusCode, http.StatusNoContent) | ||
| } | ||
| if progress, ok := callbacks.Progress("runtime-1"); !ok || progress != 42 { | ||
| t.Fatalf("progress = %v, %v; want 42, true", progress, ok) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,53 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/highcard-dev/daemon/internal/core/domain" | ||
| "github.com/highcard-dev/daemon/internal/core/ports" | ||
| ) | ||
|
|
||
| func TestWorkerProgressReporterReadsSnapshotProgress(t *testing.T) { | ||
| reports := make(chan int64, 1) | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) { | ||
| var report struct { | ||
| Token string `json:"token"` | ||
| Percentage int64 `json:"percentage"` | ||
| } | ||
| if err := json.NewDecoder(request.Body).Decode(&report); err != nil { | ||
| t.Error(err) | ||
| } | ||
| if report.Token != "token" { | ||
| t.Errorf("token = %q; want token", report.Token) | ||
| } | ||
| reports <- report.Percentage | ||
| w.WriteHeader(http.StatusNoContent) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| progress := domain.NewSnapshotProgress() | ||
| progress.Percentage.Store(37) | ||
| stop := startWorkerProgressReporter( | ||
| ports.RuntimeWorkerAction{ | ||
| RuntimeID: "runtime-1", | ||
| CallbackURL: server.URL + "/internal/v1/workers/runtime-1/complete", | ||
| CallbackToken: "token", | ||
| }, | ||
| progress, | ||
| time.Hour, | ||
| ) | ||
| defer stop() | ||
|
|
||
| select { | ||
| case percentage := <-reports: | ||
| if percentage != 37 { | ||
| t.Fatalf("percentage = %d; want 37", percentage) | ||
| } | ||
| case <-time.After(time.Second): | ||
| t.Fatal("progress was not reported") | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| package handlers | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/gofiber/fiber/v2" | ||
| "github.com/highcard-dev/daemon/internal/api" | ||
| ) | ||
|
|
||
| func TestGetHealthAuthIncludesPullProgress(t *testing.T) { | ||
| handler := NewHealthHandlerWithProgress(func(runtimeID string) (float64, bool) { | ||
| return 37, runtimeID == "scroll-1" | ||
| }) | ||
| app := fiber.New() | ||
| app.Get("/:id/api/v1/health", handler.GetHealthAuth) | ||
|
|
||
| response, err := app.Test(httptest.NewRequest(http.MethodGet, "/scroll-1/api/v1/health", nil)) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| var health api.HealthResponse | ||
| if err := json.NewDecoder(response.Body).Decode(&health); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if health.Progress == nil || *health.Progress != 37 { | ||
| t.Fatalf("progress = %v; want 37", health.Progress) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This works, but it does step outside the repo’s current API pattern.
CONTEXT.mdsays the REST surface should come from the generated OpenAPI handlers, with only/healthand websocket attach kept manual. Since this adds another handwritten callback route, I’d strongly prefer adding the progress endpoint to the callback OpenAPI contract and regeneratinginternal/callbackapiinstead of letting the route/client shape drift in two places.