github.com/gitbookio/syncgroup@v0.0.0-20181003125046-3e73b2e6a972/active_test.go (about)

     1  package syncgroup
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestActiveGroupSimple(t *testing.T) {
     8  	ag := NewActiveGroup()
     9  
    10  	// Do basic inc/dec
    11  	ag.Inc("abc")
    12  	go func() {
    13  		ag.Dec("abc")
    14  	}()
    15  	ag.WaitUntilFree("abc")
    16  
    17  	// Key should no longer exist
    18  	if ag.Has("abc") {
    19  		t.Errorf("'abc' key should no longer exist")
    20  	}
    21  
    22  	// Dummy key
    23  	if ag.Has("never_created") {
    24  		t.Errorf("Never created keys should not exist either")
    25  	}
    26  }