github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/watcher/multinotify_test.go (about)

     1  // Copyright 2019 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package watcher_test
     5  
     6  import (
     7  	gc "gopkg.in/check.v1"
     8  
     9  	"github.com/juju/juju/core/watcher"
    10  	"github.com/juju/juju/core/watcher/watchertest"
    11  )
    12  
    13  type multiNotifyWatcherSuite struct{}
    14  
    15  var _ = gc.Suite(&multiNotifyWatcherSuite{})
    16  
    17  func (*multiNotifyWatcherSuite) TestMultiNotifyWatcher(c *gc.C) {
    18  	ch0 := make(chan struct{}, 1)
    19  	w0 := watchertest.NewMockNotifyWatcher(ch0)
    20  	ch1 := make(chan struct{}, 1)
    21  	w1 := watchertest.NewMockNotifyWatcher(ch1)
    22  
    23  	// Initial events are consumed by the multiwatcher.
    24  	ch0 <- struct{}{}
    25  	ch1 <- struct{}{}
    26  
    27  	w := watcher.NewMultiNotifyWatcher(w0, w1)
    28  	wc := watchertest.NewNotifyWatcherC(c, w)
    29  	defer wc.AssertKilled()
    30  	wc.AssertOneChange()
    31  
    32  	ch0 <- struct{}{}
    33  	wc.AssertOneChange()
    34  	ch1 <- struct{}{}
    35  	wc.AssertOneChange()
    36  
    37  	ch0 <- struct{}{}
    38  	ch1 <- struct{}{}
    39  	wc.AssertOneChange()
    40  }