summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJulien Dessaux2024-12-31 11:29:58 +0100
committerJulien Dessaux2024-12-31 11:29:58 +0100
commit65e66b5e389f63eafe5d5902946b6fec974abe85 (patch)
treeca3062dc4513dd77f719042227d52831733b7d4c /cmd
parentchore(tfstated): refactor backend code to a dedicated package (diff)
downloadtfstated-65e66b5e389f63eafe5d5902946b6fec974abe85.tar.gz
tfstated-65e66b5e389f63eafe5d5902946b6fec974abe85.tar.bz2
tfstated-65e66b5e389f63eafe5d5902946b6fec974abe85.zip
chore(tfstated): prepare for listening on a second port
Diffstat (limited to 'cmd')
-rw-r--r--cmd/tfstated/main.go18
-rw-r--r--cmd/tfstated/main_test.go6
2 files changed, 14 insertions, 10 deletions
diff --git a/cmd/tfstated/main.go b/cmd/tfstated/main.go
index e6e9a38..02ddad3 100644
--- a/cmd/tfstated/main.go
+++ b/cmd/tfstated/main.go
@@ -30,17 +30,21 @@ func run(
return err
}
- httpServer := backend.Run(ctx, db, getenv, stderr)
+ backend := backend.Run(ctx, db, getenv, stderr)
+
+ <-ctx.Done()
+ shutdownCtx := context.Background()
+ shutdownCtx, shutdownCancel := context.WithTimeout(shutdownCtx, 10*time.Second)
+ defer shutdownCancel()
+
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
- <-ctx.Done()
- shutdownCtx := context.Background()
- shutdownCtx, cancel := context.WithTimeout(shutdownCtx, 10*time.Second)
- defer cancel()
- if err := httpServer.Shutdown(shutdownCtx); err != nil {
- _, _ = fmt.Fprintf(stderr, "error shutting down http server: %+v\n", err)
+ if err := backend.Shutdown(shutdownCtx); err != nil {
+ slog.Error("error shutting down backend http server", "error", err)
+ }
+ }()
}
}()
wg.Wait()
diff --git a/cmd/tfstated/main_test.go b/cmd/tfstated/main_test.go
index aa67ae8..ae9f2d7 100644
--- a/cmd/tfstated/main_test.go
+++ b/cmd/tfstated/main_test.go
@@ -15,7 +15,7 @@ import (
)
var baseURI = url.URL{
- Host: "127.0.0.1:8081",
+ Host: "127.0.0.1:8082",
Path: "/",
Scheme: "http",
}
@@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
case "TFSTATED_HOST":
return "127.0.0.1"
case "TFSTATED_PORT":
- return "8081"
+ return "8082"
case "VERSIONS_HISTORY_LIMIT":
return "3"
default:
@@ -59,7 +59,7 @@ func TestMain(m *testing.M) {
getenv,
os.Stderr,
)
- err = waitForReady(ctx, 5*time.Second, "http://127.0.0.1:8081/healthz")
+ err = waitForReady(ctx, 5*time.Second, "http://127.0.0.1:8082/healthz")
if err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)