-
Notifications
You must be signed in to change notification settings - Fork 74
feat: run the worker handoff over Unix sockets on Windows #1231
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
charleswool
wants to merge
5
commits into
eraser-dev:main
Choose a base branch
from
charleswool:feat/windows-worker-ipc
base: main
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
5 commits
Select commit
Hold shift + click to select a range
9daeb94
refactor: gather the worker handoff into pkg/utils
charleswool ed03cad
feat: run the worker handoff over Unix sockets on Windows
charleswool 8c925e1
fix: correct the socket path limit and make Close idempotent
charleswool 118719d
fix: publish the collector completion endpoint before the payload
charleswool e7455e1
fix: close the FIFO descriptor on every path
charleswool 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
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,113 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/eraser-dev/eraser/api/unversioned" | ||
| ) | ||
|
|
||
| // These run against whichever implementation the platform selects: FIFOs on | ||
| // Unix, Unix domain sockets on Windows. Keeping them build-tag free is the point | ||
| // -- the two implementations have to stay behaviorally identical. | ||
|
|
||
| // shortTempDir keeps paths well inside the sun_path limit that applies to the | ||
| // socket implementation. | ||
| func shortTempDir(t *testing.T) string { | ||
| t.Helper() | ||
|
|
||
| dir, err := os.MkdirTemp("", "h") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| t.Cleanup(func() { _ = os.RemoveAll(dir) }) | ||
|
|
||
| return dir | ||
| } | ||
|
|
||
| func TestImagesHandoffRoundTrip(t *testing.T) { | ||
| path := filepath.Join(shortTempDir(t), "images") | ||
|
|
||
| want := []unversioned.Image{ | ||
| {ImageID: "sha256:aaaa", Names: []string{"repo/one:v1"}}, | ||
| {ImageID: "sha256:bbbb", Names: []string{"repo/two:v2"}}, | ||
| } | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { errCh <- WriteImagesPipe(path, want) }() | ||
|
|
||
| got, err := ReadImagesPipe(context.Background(), path) | ||
| if err != nil { | ||
| t.Fatalf("ReadImagesPipe: %v", err) | ||
| } | ||
| if err := <-errCh; err != nil { | ||
| t.Fatalf("WriteImagesPipe: %v", err) | ||
| } | ||
|
|
||
| if len(got) != len(want) { | ||
| t.Fatalf("got %d images, want %d", len(got), len(want)) | ||
| } | ||
| for i := range want { | ||
| if got[i].ImageID != want[i].ImageID { | ||
| t.Errorf("image %d = %q, want %q", i, got[i].ImageID, want[i].ImageID) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestCompletionHandoffRoundTrip(t *testing.T) { | ||
| path := filepath.Join(shortTempDir(t), "complete") | ||
|
|
||
| pipe, err := CreateCompletionPipe(path) | ||
| if err != nil { | ||
| t.Fatalf("CreateCompletionPipe: %v", err) | ||
| } | ||
| defer func() { _ = pipe.Close() }() | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { errCh <- WriteCompletionPipe(path) }() | ||
|
|
||
| data, err := pipe.Await() | ||
| if err != nil { | ||
| t.Fatalf("Await: %v", err) | ||
| } | ||
| if err := <-errCh; err != nil { | ||
| t.Fatalf("WriteCompletionPipe: %v", err) | ||
| } | ||
|
|
||
| if string(data) != EraseCompleteMessage { | ||
| t.Errorf("payload = %q, want %q", string(data), EraseCompleteMessage) | ||
| } | ||
| } | ||
|
|
||
| // The remover infers "the scanner is disabled" from this error, so it has to | ||
| // keep satisfying os.IsNotExist on both platforms. | ||
| func TestWriteCompletionPipeAbsentPeerIsNotExist(t *testing.T) { | ||
| path := filepath.Join(shortTempDir(t), "no-such-peer") | ||
|
|
||
| err := WriteCompletionPipe(path) | ||
| if err == nil { | ||
| t.Fatal("expected an error writing to an endpoint nobody published") | ||
| } | ||
| if !os.IsNotExist(err) { | ||
| t.Errorf("os.IsNotExist(%v) = false, want true", err) | ||
| } | ||
| } | ||
|
|
||
| func TestCompletionPipeCloseIsIdempotentlySafe(t *testing.T) { | ||
| path := filepath.Join(shortTempDir(t), "closed") | ||
|
|
||
| pipe, err := CreateCompletionPipe(path) | ||
| if err != nil { | ||
| t.Fatalf("CreateCompletionPipe: %v", err) | ||
| } | ||
|
|
||
| // the scanner defers Close and the collector also closes explicitly | ||
| if err := pipe.Close(); err != nil { | ||
| t.Errorf("first Close: %v", err) | ||
| } | ||
| if err := pipe.Close(); err != nil { | ||
| t.Errorf("second Close: %v", err) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.