Skip to content

Commit

Permalink
service discovery: tests: test binary lives until terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb committed Nov 27, 2024
1 parent 8f7cb53 commit cab5bd8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func TestGoDetector(t *testing.T) {
require.NoError(t, cmd.Start())
t.Cleanup(func() {
_ = cmd.Process.Kill()
cmd.Wait()
})
require.Eventually(t, func() bool {
if cmd.Process.Pid == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,32 @@
package main

import (
"time"
"os"
"os/signal"
"syscall"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
// Start the tracer
tracer.Start()
time.Sleep(time.Second * 20)

// Create a channel to listen for OS signals
signalChan := make(chan os.Signal, 1)
done := make(chan bool, 1)

// Notify on SIGINT and SIGTERM
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT)

go func() {
<-signalChan // Wait for a termination signal
done <- true
}()

// Print a message and wait for a signal
println("Running... Press Ctrl+C to exit.")

<-done // Block until a signal is received
println("Gracefully shutting down.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package main

import (
"fmt"
"time"
"os"
"os/signal"
"syscall"

"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
)
Expand All @@ -20,5 +22,21 @@ func main() {
fmt.Println(err)
}

time.Sleep(time.Second * 20)
// Create a channel to listen for OS signals
signalChan := make(chan os.Signal, 1)
done := make(chan bool, 1)

// Notify on SIGINT and SIGTERM
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT)

go func() {
<-signalChan // Wait for a termination signal
done <- true
}()

// Print a message and wait for a signal
println("Running... Press Ctrl+C to exit.")

<-done // Block until a signal is received
println("Gracefully shutting down.")
}

0 comments on commit cab5bd8

Please sign in to comment.