scouting: Change background_task implementation
Instead of manually implementing a ticker, this patch switches over to
using `time.Ticker`. The functionality should be identical.
This patch also adds a small test to make sure that the bare
functionality is working.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I54acfc5280b3541f3021dbe35d79e7db0adcc5f6
diff --git a/scouting/background_task/background_task_test.go b/scouting/background_task/background_task_test.go
new file mode 100644
index 0000000..5326d14
--- /dev/null
+++ b/scouting/background_task/background_task_test.go
@@ -0,0 +1,21 @@
+package background_task
+
+import (
+ "testing"
+ "time"
+)
+
+func TestBackgroundTask(t *testing.T) {
+ task := New(100 * time.Millisecond)
+ defer task.Stop()
+
+ counter := 0
+ task.Start(func() {
+ counter += 1
+ })
+
+ // Block until we've seeen 10 timer ticks.
+ for counter < 10 {
+ time.Sleep(100 * time.Millisecond)
+ }
+}