services/device/internal/impl: remove redundant code in tests

This CL deletes some redundant code in the device manger unit tests.

Change-Id: Ie3e88193245c1a0f5a19f089b07d551944a1f730
diff --git a/services/device/internal/impl/daemonreap/daemon_reaping_test.go b/services/device/internal/impl/daemonreap/daemon_reaping_test.go
index 10c3027..945d463 100644
--- a/services/device/internal/impl/daemonreap/daemon_reaping_test.go
+++ b/services/device/internal/impl/daemonreap/daemon_reaping_test.go
@@ -46,7 +46,7 @@
 
 	utiltest.VerifyState(t, ctx, device.InstanceStateRunning, appID, instance1ID)
 	syscall.Kill(int(pid), 9)
-	pollingWait(t, int(pid))
+	utiltest.PollingWait(t, int(pid))
 
 	// Start a second instance of the app which will force polling to happen.
 	// During this polling, the reaper will restart app instance1
@@ -71,7 +71,7 @@
 	pingCh.WaitForPingArgs(t)
 	// Kill the application again.
 	syscall.Kill(int(pid), 9)
-	pollingWait(t, int(pid))
+	utiltest.PollingWait(t, int(pid))
 
 	// Start and stop instance 2 again to force two polling cycles.
 	utiltest.RunApp(t, ctx, appID, instance2ID)
@@ -90,17 +90,3 @@
 	dmh.Expect("dm terminated")
 	dmh.ExpectEOF()
 }
-
-// pollingWait waits until the specificed process is actually dead so that
-// that the test can be certain that the process is actually dead before
-// continuing.
-func pollingWait(t *testing.T, pid int) {
-	for {
-		switch err := syscall.Kill(pid, 0); {
-		case err == syscall.ESRCH:
-			return
-		case err != nil:
-			t.Fatalf("syscall.Kill not working as expected: %v", err)
-		}
-	}
-}
diff --git a/services/device/internal/impl/daemonreap/instance_reaping_kill_test.go b/services/device/internal/impl/daemonreap/instance_reaping_kill_test.go
index b756afd..32216e6 100644
--- a/services/device/internal/impl/daemonreap/instance_reaping_kill_test.go
+++ b/services/device/internal/impl/daemonreap/instance_reaping_kill_test.go
@@ -10,7 +10,6 @@
 	"os"
 	"syscall"
 	"testing"
-	"time"
 
 	"v.io/v23/services/device"
 	"v.io/x/ref"
@@ -66,15 +65,7 @@
 
 	// Kill instance[0] and wait until it exits before proceeding.
 	syscall.Kill(pid, 9)
-	timeOut := time.After(5 * time.Second)
-	for syscall.Kill(pid, 0) == nil {
-		select {
-		case <-timeOut:
-			t.Fatalf("Timed out waiting for PID %v to terminate", pid)
-		case <-time.After(time.Millisecond):
-			// Try again.
-		}
-	}
+	utiltest.PollingWait(t, pid)
 
 	// Run another device manager to replace the dead one.
 	dmh = servicetest.RunCommand(t, sh, dmEnv, utiltest.DeviceManager, "dm", root, helperPath, "unused_app_repo_name", "unused_curr_link")
diff --git a/services/device/internal/impl/utiltest/helpers.go b/services/device/internal/impl/utiltest/helpers.go
index 737df6b..3fed3e1 100644
--- a/services/device/internal/impl/utiltest/helpers.go
+++ b/services/device/internal/impl/utiltest/helpers.go
@@ -15,6 +15,7 @@
 	"regexp"
 	"sort"
 	"strings"
+	"syscall"
 	"testing"
 	"time"
 
@@ -785,3 +786,17 @@
 	}
 	return int(v.Int())
 }
+
+// PollingWait polls a given process to make sure that it has exited
+// before continuing or fails with a time-out.
+func PollingWait(t *testing.T, pid int) {
+	timeOut := time.After(5 * time.Second)
+	for syscall.Kill(pid, 0) == nil {
+		select {
+		case <-timeOut:
+			t.Fatalf("Timed out waiting for PID %v to terminate", pid)
+		case <-time.After(time.Millisecond):
+			// Try again.
+		}
+	}
+}