func TestRegister(t *testing.T) {
	tests := []struct {
		runImmediately bool
	}{
		{true},
		{false},
	}
	for _, tt := range tests {
		callCount := 0
		delay := time.Millisecond * 500
		j := Register(func() {
			callCount++
		}, delay, tt.runImmediately)
		if j == nil {
			t.Fatal("Unexpected nil response from Register")
		}
		time.Sleep(time.Millisecond * 100)
		if callCount > 0 && !tt.runImmediately {
			t.Fatalf("Unexpected callCount for runImmediately=false, expected=%v, got=%v", 0, callCount)
		} else if callCount == 0 && tt.runImmediately {
			t.Fatalf("Unexpected callCount for runImmediately=true, expected=%v, got=%v", 1, callCount)
		}
		if tt.runImmediately {
			callCount--
		}
		for i := 1; i <= 2; i++ {
			time.Sleep(delay + time.Millisecond*100)
			if callCount != i {
				t.Fatalf("Unexpected callCount, expected=%v, got=%v", i, callCount)
			}
		}
	}
}
TODO: These tests are almost certainly prone to race conditions.
package job
import (
	"testing"
	"time"
)