Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1003)

Unified Diff: state/testing/watcher.go

Issue 12352044: state: hopefully make tests more reliable
Patch Set: state: hopefully make tests more reliable Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/state_test.go ('k') | state/unit_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/testing/watcher.go
=== modified file 'state/testing/watcher.go'
--- state/testing/watcher.go 2013-07-22 10:29:03 +0000
+++ state/testing/watcher.go 2013-08-02 18:20:04 +0000
@@ -51,9 +51,8 @@
// the behaviour of any watcher that uses a <-chan struct{}.
type NotifyWatcherC struct {
*C
- State *state.State
- Watcher NotifyWatcher
- FullSync bool
+ State *state.State
+ Watcher NotifyWatcher
}
// NewNotifyWatcherC returns a NotifyWatcherC that checks for aggressive
@@ -66,20 +65,8 @@
}
}
-// NewLaxNotifyWatcherC returns a NotifyWatcherC that runs a full watcher
-// sync before reading from the watcher's Changes channel, and hence cannot
-// verify real-world coalescence behaviour.
-func NewLaxNotifyWatcherC(c *C, st *state.State, w NotifyWatcher) NotifyWatcherC {
- return NotifyWatcherC{
- C: c,
- State: st,
- Watcher: w,
- FullSync: true,
- }
-}
-
func (c NotifyWatcherC) AssertNoChange() {
- c.State.StartSync()
+ c.State.Sync()
select {
case _, ok := <-c.Watcher.Changes():
c.Fatalf("watcher sent unexpected change: (_, %v)", ok)
@@ -88,11 +75,7 @@
}
func (c NotifyWatcherC) AssertOneChange() {
- if c.FullSync {
- c.State.Sync()
- } else {
- c.State.StartSync()
- }
+ c.State.Sync()
select {
case _, ok := <-c.Watcher.Changes():
c.Assert(ok, Equals, true)
@@ -115,9 +98,8 @@
// the behaviour of any watcher that uses a <-chan []string.
type StringsWatcherC struct {
*C
- State *state.State
- Watcher StringsWatcher
- FullSync bool
+ State *state.State
+ Watcher StringsWatcher
}
// NewStringsWatcherC returns a StringsWatcherC that checks for aggressive
@@ -130,25 +112,13 @@
}
}
-// NewLaxStringsWatcherC returns a StringsWatcherC that runs a full watcher
-// sync before reading from the watcher's Changes channel, and hence cannot
-// verify real-world coalescence behaviour.
-func NewLaxStringsWatcherC(c *C, st *state.State, w StringsWatcher) StringsWatcherC {
- return StringsWatcherC{
- C: c,
- State: st,
- Watcher: w,
- FullSync: true,
- }
-}
-
type StringsWatcher interface {
Stop() error
Changes() <-chan []string
}
func (c StringsWatcherC) AssertNoChange() {
- c.State.StartSync()
+ c.State.Sync()
select {
case actual, ok := <-c.Watcher.Changes():
c.Fatalf("watcher sent unexpected change: (%v, %v)", actual, ok)
@@ -159,11 +129,7 @@
// AssertChange asserts the given list of changes was reported by
// the watcher, but does not assume there are no following changes.
func (c StringsWatcherC) AssertChange(expect ...string) {
- if c.FullSync {
- c.State.Sync()
- } else {
- c.State.StartSync()
- }
+ c.State.Sync()
timeout := time.After(testing.LongWait)
var actual []string
loop:
« no previous file with comments | « state/state_test.go ('k') | state/unit_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b