-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WATCHER: Fix bug wherein multiple consumers will try and process the …
…same event. Add tests for queue and poller.
- Loading branch information
Showing
5 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
package watcher | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
var ( | ||
pollInterval = 1 | ||
) | ||
|
||
func TestPoller(t *testing.T) { | ||
t.Run("It successfully notifies of a new event", func(t *testing.T) { | ||
pw := setupPathwatcher("/tmp") | ||
pw.Poll(pollInterval) | ||
|
||
ev := eventSetup(t) | ||
pw.Queue.Add(*ev) | ||
|
||
if pw.Queue.Size() != 1 { | ||
t.Errorf("Queue size did not increase. want=%d, got=%d", 1, pw.Queue.Size()) | ||
} | ||
<-time.After(3 * time.Second) | ||
|
||
if pw.Queue.Size() != 0 { | ||
t.Errorf("Queue size did not decrease. want=%d, got=%d", 0, pw.Queue.Size()) | ||
} | ||
}) | ||
} | ||
|
||
func setupPathwatcher(path string) *PathWatcher { | ||
return &PathWatcher{ | ||
Queue: NewQueue(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters