This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
test: enhance DummyExecutor #39
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb575a2
test: enhance DummyExecutor
tzdybal aea8bf3
chore: fix linter errors
tzdybal 6f65726
feat: handle signals, use channel instead of WaitGroup
tzdybal 09d6483
refactor: improve flag parsing and logs
tzdybal 71c9376
fix: remove block from pending after finalization
tzdybal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "net" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
|
|
||
| "google.golang.org/grpc" | ||
|
|
||
| grpcproxy "github.com/rollkit/go-execution/proxy/grpc" | ||
| "github.com/rollkit/go-execution/test" | ||
| pb "github.com/rollkit/go-execution/types/pb/execution" | ||
| ) | ||
|
|
||
| func main() { | ||
| listenAddress, err := parseListenAddress() | ||
| if err != nil { | ||
| log.Fatalf("Failed to parse listen address: %v\n", err) | ||
| } | ||
| listener, err := net.Listen("tcp4", listenAddress) | ||
| if err != nil { | ||
| log.Fatalf("Failed to listen on %q: %v\n", listenAddress, err) | ||
| } | ||
| defer func() { | ||
| _ = listener.Close() | ||
| }() | ||
|
|
||
| log.Println("Creating Dummy Executor and gRPC server") | ||
| dummy := test.NewDummyExecutor() | ||
| server := grpcproxy.NewServer(dummy, grpcproxy.DefaultConfig()) | ||
| s := grpc.NewServer() | ||
| pb.RegisterExecutionServiceServer(s, server) | ||
|
|
||
| // Setup signal handling | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
|
||
| doneChan := make(chan interface{}, 1) | ||
| go func() { | ||
| log.Printf("Serving (%s)...\n", listenAddress) | ||
| log.Println("Type Ctrl+C to shutdown") | ||
| if err := s.Serve(listener); err != nil && !errors.Is(err, grpc.ErrServerStopped) { | ||
| log.Fatalf("Server exited with error: %v\n", err) | ||
| } | ||
| doneChan <- nil | ||
| }() | ||
|
|
||
| // Handle shutdown signal | ||
| go func() { | ||
| <-sigChan | ||
| log.Println("Received shutdown signal") | ||
| s.GracefulStop() | ||
| }() | ||
|
|
||
| <-doneChan | ||
| log.Println("Server stopped") | ||
| } | ||
|
|
||
| func parseListenAddress() (string, error) { | ||
| var listenAddress string | ||
| flag.StringVar(&listenAddress, "address", "127.0.0.1:40041", "gRPC server listen address") | ||
| flag.Parse() | ||
|
|
||
| _, port, err := net.SplitHostPort(listenAddress) | ||
| if err != nil { | ||
| return "", fmt.Errorf("invalid address format %q: %v", listenAddress, err) | ||
| } | ||
| if port == "" { | ||
| return "", errors.New("port cannot be empty") | ||
| } | ||
|
|
||
| return listenAddress, nil | ||
| } | ||
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
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.