-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45ac0c0
commit a38eb5c
Showing
2 changed files
with
49 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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,49 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2023-present Datadog, Inc. | ||
|
||
//go:build unix | ||
|
||
package gls | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestSignal tests that the GLS is correctly set even when the code comes from a signal handler. | ||
func TestSignal(t *testing.T) { | ||
if !orchestrionEnabled { | ||
t.Skip("Orchestrion is not enabled") | ||
} | ||
|
||
expected := "I am inside a signal handler" | ||
|
||
set(nil) | ||
|
||
doneSigChan := make(chan struct{}, 1) | ||
checkChan := make(chan struct{}, 1) | ||
doneCheckChan := make(chan struct{}, 1) | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGUSR1) | ||
|
||
go func() { | ||
<-sigChan | ||
set(expected) | ||
doneSigChan <- struct{}{} | ||
|
||
<-checkChan | ||
require.Equal(t, expected, get()) | ||
doneCheckChan <- struct{}{} | ||
}() | ||
|
||
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1) | ||
<-doneSigChan | ||
checkChan <- struct{}{} | ||
<-doneCheckChan | ||
} |