aboutsummaryrefslogtreecommitdiff
path: root/internal/queue/queue_test.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-02-19 16:15:04 -0500
committerJulie Qiu <julie@golang.org>2020-04-06 15:50:52 -0400
commitc0dfa6a74dcef191ce8ae99635a7cfdcc4c4ef83 (patch)
treed34f4e607e258cfb6d7e75dd4ad87ca9e87a03b3 /internal/queue/queue_test.go
parentf2324fa41381e39dd9f6c88786122d2236e483ea (diff)
downloadgo-x-pkgsite-c0dfa6a74dcef191ce8ae99635a7cfdcc4c4ef83.tar.xz
internal/queue: create package
The code for creating a new package is moved to internal/queue. This allows for adding items to a task queue from the frontend, without importing the entire internal/etl package. No logic is changed, except the signature of queue.InMemoryQueue.process, so that etl.FetchAndUpdateState can be passed in, and the entire internal/etl package does not need to be imported by internal/queue, which would lead to a circular import. Updates b/135954292 Change-Id: I33a6418c73d85e15c4aa5593d633e19eb7e4eb1b Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/671014 Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/queue/queue_test.go')
-rw-r--r--internal/queue/queue_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/queue/queue_test.go b/internal/queue/queue_test.go
new file mode 100644
index 00000000..3933325b
--- /dev/null
+++ b/internal/queue/queue_test.go
@@ -0,0 +1,30 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package queue
+
+import (
+ "testing"
+ "time"
+)
+
+func TestNewTaskID(t *testing.T) {
+ // Verify that the task ID is the same within taskIDChangeInterval and changes
+ // afterwards.
+ const (
+ module = "mod"
+ version = "ver"
+ )
+
+ tm := time.Now().Truncate(taskIDChangeInterval)
+ id1 := newTaskID(module, version, tm)
+ id2 := newTaskID(module, version, tm.Add(taskIDChangeInterval/2))
+ if id1 != id2 {
+ t.Error("wanted same task ID, got different")
+ }
+ id3 := newTaskID(module, version, tm.Add(taskIDChangeInterval+1))
+ if id1 == id3 {
+ t.Error("wanted different task ID, got same")
+ }
+}