Skip to content

Commit

Permalink
Isolate signal test to UNIX only
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Jul 15, 2024
1 parent 45ac0c0 commit a38eb5c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
35 changes: 0 additions & 35 deletions _integration-tests/gls/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
package gls

import (
"os"
"os/signal"
"runtime"
"sync"
"syscall"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -46,38 +43,6 @@ func TestCGO(t *testing.T) {
require.Equal(t, expected, get())
}

// 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
}

func TestConcurrency(t *testing.T) {
if !orchestrionEnabled {
t.Skip("Orchestrion is not enabled")
Expand Down
49 changes: 49 additions & 0 deletions _integration-tests/gls/access_unix_test.go
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
}

0 comments on commit a38eb5c

Please sign in to comment.