github.com/lyft/flytestdlib@v0.3.12-0.20210213045714-8cdd111ecda1/atomic/non_blocking_lock_test.go (about)

     1  package atomic
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNewNonBlockingLock(t *testing.T) {
    10  	lock := NewNonBlockingLock()
    11  	assert.True(t, lock.TryLock(), "Unexpected lock acquire failure")
    12  	assert.False(t, lock.TryLock(), "already-acquired lock acquired again")
    13  	lock.Release()
    14  	assert.True(t, lock.TryLock(), "Unexpected lock acquire failure")
    15  }