-
Notifications
You must be signed in to change notification settings - Fork 16
Provide support for deferred services #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8847ac
fix: Allow for itests components to be deferred after init
darkrift 11ebca0
fix test
darkrift eafe5db
more cleanup
darkrift 17206e0
Merge branch 'master' into issue38_take2
darkrift 2e0144c
Add non-deferred to deferred check at analyais time
darkrift 2d554c0
fix comment message
darkrift 7e403db
Merge branch 'master' into issue38_take2
darkrift eb5b51e
fix deferred for tasks
darkrift 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
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,60 @@ | ||
| load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test") | ||
| load("@rules_itest//:itest.bzl", "itest_service", "itest_task", "service_test") | ||
| load(":tests.bzl", "tests") | ||
|
|
||
| tests() | ||
|
|
||
| go_library( | ||
| name = "deferred_lib", | ||
| srcs = ["deferred_service.go"], | ||
| importpath = "rules_itest/tests/deferred", | ||
| visibility = ["//visibility:private"], | ||
| ) | ||
|
|
||
| go_binary( | ||
| name = "deferred", | ||
| embed = [":deferred_lib"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "deferred_test", | ||
| srcs = ["start_deferred_service_test.go"], | ||
| embed = [":deferred_lib"], | ||
| tags = ["manual"], | ||
| deps = ["//svcctl"], | ||
| ) | ||
|
|
||
| service_test( | ||
| name = "deferred_service_test", | ||
| services = [":deferred_itest_service"], | ||
| test = ":deferred_test", | ||
| ) | ||
|
|
||
| itest_service( | ||
| name = "deferred_itest_service", | ||
| args = [ | ||
| "$${PORT}", | ||
| ], | ||
| autoassign_port = True, | ||
| deferred = True, | ||
| exe = ":deferred", | ||
| http_health_check_address = "http://localhost:$${PORT}/healthz", | ||
| tags = ["requires-network"], | ||
| ) | ||
|
|
||
| itest_service( | ||
| name = "deferred_task", | ||
| deferred = True, | ||
| exe = "@rules_itest//:exit0", | ||
| hygienic = False, | ||
| ) | ||
|
|
||
| itest_service( | ||
| name = "non_deferred_depends_on_deferred_should_fail", | ||
| exe = "@rules_itest//:exit0", | ||
| tags = ["manual"], | ||
| deps = [ | ||
| ":deferred_task", | ||
| ], | ||
| ) |
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,95 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "strconv" | ||
| "sync" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| var ( | ||
| mu sync.RWMutex | ||
| value string | ||
| ) | ||
|
|
||
| func main() { | ||
| mux := http.NewServeMux() | ||
| mux.HandleFunc("/healthz", healthHandler) | ||
| mux.HandleFunc("/update", updateHandler) | ||
| mux.HandleFunc("/value", valueHandler) | ||
|
|
||
| port, err := strconv.ParseInt(os.Args[1], 10, 64) | ||
| if err != nil { | ||
| log.Fatalf("Invalid port: %v", err) | ||
| } | ||
|
|
||
| server := &http.Server{ | ||
| Addr: "0.0.0.0:" + strconv.FormatInt(port, 10), | ||
| Handler: mux, | ||
| } | ||
|
|
||
| // Listen for SIGTERM for graceful shutdown | ||
| stop := make(chan os.Signal, 1) | ||
| signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) | ||
|
|
||
| go func() { | ||
| log.Println("Server starting on :" + strconv.FormatInt(port, 10)) | ||
| if err := server.ListenAndServe(); err != http.ErrServerClosed { | ||
| log.Fatalf("ListenAndServe: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| <-stop | ||
| log.Println("Shutting down...") | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| if err := server.Shutdown(ctx); err != nil { | ||
| log.Fatalf("Server Shutdown Failed:%+v", err) | ||
| } | ||
| log.Println("Server exited gracefully") | ||
| } | ||
|
|
||
| func healthHandler(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write([]byte(`ok`)) | ||
| } | ||
|
|
||
| func updateHandler(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| http.Error(w, "Only POST allowed", http.StatusMethodNotAllowed) | ||
| return | ||
| } | ||
| var payload struct { | ||
| Value string `json:"value"` | ||
| } | ||
| err := json.NewDecoder(r.Body).Decode(&payload) | ||
| if err != nil { | ||
| http.Error(w, "Invalid JSON", http.StatusBadRequest) | ||
| return | ||
| } | ||
| mu.Lock() | ||
| value = payload.Value | ||
| mu.Unlock() | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write([]byte(`updated`)) | ||
| } | ||
|
|
||
| func valueHandler(w http.ResponseWriter, r *http.Request) { | ||
| mu.RLock() | ||
| defer mu.RUnlock() | ||
| resp := struct { | ||
| Value string `json:"value"` | ||
| }{ | ||
| Value: value, | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| json.NewEncoder(w).Encode(resp) | ||
| } |
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.
i think
groupalso needs a deferred prop, otherwise you can have (non-deferred service) depend on (group) depend on (deferred service) and it will defeat the check you addedThere 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.
same thing with tasks, right? let's just add the attribute on all of them