github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/nomad/state/notify_test.go (about)

     1  package state
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestNotifyGroup(t *testing.T) {
     8  	grp := &NotifyGroup{}
     9  
    10  	ch1 := grp.WaitCh()
    11  	ch2 := grp.WaitCh()
    12  
    13  	select {
    14  	case <-ch1:
    15  		t.Fatalf("should block")
    16  	default:
    17  	}
    18  	select {
    19  	case <-ch2:
    20  		t.Fatalf("should block")
    21  	default:
    22  	}
    23  
    24  	grp.Notify()
    25  
    26  	select {
    27  	case <-ch1:
    28  	default:
    29  		t.Fatalf("should not block")
    30  	}
    31  	select {
    32  	case <-ch2:
    33  	default:
    34  		t.Fatalf("should not block")
    35  	}
    36  
    37  	// Should be unregistered
    38  	ch3 := grp.WaitCh()
    39  	grp.Notify()
    40  
    41  	select {
    42  	case <-ch1:
    43  		t.Fatalf("should block")
    44  	default:
    45  	}
    46  	select {
    47  	case <-ch2:
    48  		t.Fatalf("should block")
    49  	default:
    50  	}
    51  	select {
    52  	case <-ch3:
    53  	default:
    54  		t.Fatalf("should not block")
    55  	}
    56  }
    57  
    58  func TestNotifyGroup_Clear(t *testing.T) {
    59  	grp := &NotifyGroup{}
    60  
    61  	ch1 := grp.WaitCh()
    62  	grp.Clear(ch1)
    63  
    64  	grp.Notify()
    65  
    66  	// Should not get anything
    67  	select {
    68  	case <-ch1:
    69  		t.Fatalf("should not get message")
    70  	default:
    71  	}
    72  }