github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/signal/signal_test.go (about)

     1  package signal_test
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/kyma-incubator/compass/components/director/pkg/signal"
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestHandleInterrupts(t *testing.T) {
    15  	ctx, cancel := context.WithCancel(context.TODO())
    16  	term := make(chan os.Signal)
    17  	signal.HandleInterrupts(ctx, cancel, term)
    18  	term <- os.Interrupt
    19  	require.Eventually(t, func() bool {
    20  		return assert.Equal(t, ctx.Err(), context.Canceled)
    21  	}, time.Second, 50*time.Millisecond)
    22  }