Ubuntu Pastebin

Paste from dfc at Tue, 21 Jun 2016 04:21:34 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
diff --git a/state/allwatcher_internal_test.go b/state/allwatcher_internal_test.go
index 5de519f..512e0e5 100644
--- a/state/allwatcher_internal_test.go
+++ b/state/allwatcher_internal_test.go
@@ -1052,16 +1052,16 @@ func (s *allWatcherStateSuite) TestStateWatcherTwoModels(c *gc.C) {
 				if test.setUpState != nil {
 					test.setUpState(st)
 					// Consume events from setup.
-					w.AssertChanges()
-					w.AssertNoChange()
-					otherW.AssertNoChange()
+					w.AssertChanges(c)
+					w.AssertNoChange(c)
+					otherW.AssertNoChange(c)
 				}
 
 				test.triggerEvent(st)
 				// Check event was isolated to the correct watcher.
-				w.AssertChanges()
-				w.AssertNoChange()
-				otherW.AssertNoChange()
+				w.AssertChanges(c)
+				w.AssertNoChange(c)
+				otherW.AssertNoChange(c)
 			}
 			otherState := s.newState(c)
 
@@ -1071,8 +1071,8 @@ func (s *allWatcherStateSuite) TestStateWatcherTwoModels(c *gc.C) {
 			defer w2.Stop()
 
 			// The first set of deltas is empty, reflecting an empty model.
-			w1.AssertNoChange()
-			w2.AssertNoChange()
+			w1.AssertNoChange(c)
+			w2.AssertNoChange(c)
 			checkIsolationForEnv(s.state, w1, w2)
 			checkIsolationForEnv(otherState, w2, w1)
 		}()
@@ -3047,10 +3047,11 @@ func newTestWatcher(b Backing, st *State, c *gc.C) *testWatcher {
 		deltas: make(chan []multiwatcher.Delta),
 	}
 	go func() {
+		defer close(tw.deltas)
 		for {
 			deltas, err := tw.w.Next()
 			if err != nil {
-				break
+				return
 			}
 			tw.deltas <- deltas
 		}
@@ -3058,31 +3059,6 @@ func newTestWatcher(b Backing, st *State, c *gc.C) *testWatcher {
 	return tw
 }
 
-func (tw *testWatcher) Next(timeout time.Duration) []multiwatcher.Delta {
-	select {
-	case d := <-tw.deltas:
-		return d
-	case <-time.After(timeout):
-		return nil
-	}
-}
-
-func (tw *testWatcher) NumDeltas() int {
-	count := 0
-	tw.st.StartSync()
-	for {
-		// TODO(mjs) - this is somewhat fragile. There are no
-		// guarentees that the watcher will be able to return deltas
-		// in ShortWait time.
-		deltas := tw.Next(testing.ShortWait)
-		if len(deltas) == 0 {
-			break
-		}
-		count += len(deltas)
-	}
-	return count
-}
-
 func (tw *testWatcher) All(expectedCount int) []multiwatcher.Delta {
 	var allDeltas []multiwatcher.Delta
 	tw.st.StartSync()
@@ -3096,21 +3072,22 @@ func (tw *testWatcher) All(expectedCount int) []multiwatcher.Delta {
 
 	now := time.Now()
 	maxTime := now.Add(maxDuration)
+done:
 	for {
 		remaining := maxTime.Sub(now)
-		if remaining < time.Duration(0) {
-			break // timed out
-		}
-
-		deltas := tw.Next(remaining)
-		if len(deltas) > 0 {
-			allDeltas = append(allDeltas, deltas...)
-			if len(allDeltas) >= expectedCount {
-				break
+		select {
+		case deltas := <-tw.deltas:
+			if len(deltas) > 0 {
+				allDeltas = append(allDeltas, deltas...)
+				if len(allDeltas) >= expectedCount {
+					break done
+				}
 			}
+			now = time.Now()
+		case <-time.After(remaining):
+			// timed out
+			break done
 		}
-
-		now = time.Now()
 	}
 	return allDeltas
 }
@@ -3121,12 +3098,25 @@ func (tw *testWatcher) Stop() {
 	tw.c.Assert(tw.b.Release(), jc.ErrorIsNil)
 }
 
-func (tw *testWatcher) AssertNoChange() {
-	tw.c.Assert(tw.NumDeltas(), gc.Equals, 0)
+func (tw *testWatcher) AssertNoChange(c *gc.C) {
+	tw.st.StartSync()
+	select {
+	case <-tw.deltas:
+		c.Error("change detected")
+	case <-time.After(testing.ShortWait):
+		// expected
+	}
 }
 
-func (tw *testWatcher) AssertChanges() {
-	tw.c.Assert(tw.NumDeltas(), jc.GreaterThan, 0)
+func (tw *testWatcher) AssertChanges(c *gc.C) {
+	tw.st.StartSync()
+	select {
+	case d, ok := <-tw.deltas:
+		c.Assert(ok, gc.Equals, true)
+		c.Assert(len(d), jc.GreaterThan, 0)
+	case <-time.After(testing.ShortWait):
+		c.Error("no change detected")
+	}
 }
 
 type entityInfoSlice []multiwatcher.EntityInfo
Download as text