44 lines
2.1 KiB
Go
44 lines
2.1 KiB
Go
package link
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// An ask a machine holds but does not start gets no heartbeat, and the bus hands it to another machine after the ack
|
|
// wait, so two machines run one check (issue 1649).
|
|
|
|
// A fetch's server-side pull request ends clearly before the fetch does, so the server's answer and any message it could still
|
|
// deliver come inside the fetch and never into a buffer nobody reads while the machine builds.
|
|
func TestAFetchsPullRequestEndsClearlyBeforeTheFetchDoes(t *testing.T) {
|
|
for name, wait := range map[string]time.Duration{"a check queue": checkTakeWait, "the idle wait": takeIdleWait} {
|
|
if margin := wait - fetchExpiryOf(wait); margin < minFetchMargin {
|
|
t.Errorf("%s: the pull request ends %v before a fetch of %v does; want at least %v", name, margin, wait, minFetchMargin)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAnAskAnotherBuilderIsRunningIsADuplicateAndYoursIsNot(t *testing.T) {
|
|
r := aPullCheck("build-1", 423, "head-4771ee53aa", "trunk-0123456789", false)
|
|
run := CheckRunning{Head: r.Ref, Trunk: "trunk-0123456789", Builder: "shanks", Build: "build-1", Started: time.Now().Add(-time.Minute), Seen: time.Now().Add(-4 * time.Second)}
|
|
dead := run
|
|
dead.Seen = time.Now().Add(-60 * time.Second)
|
|
for name, c := range map[string]struct {
|
|
running CheckRunning
|
|
found bool
|
|
me string
|
|
dup bool
|
|
}{
|
|
"another builder runs this very ask": {run, true, "ace", true},
|
|
"its builder stopped renewing the key a minute ago": {dead, true, "ace", false},
|
|
"this builder runs it itself": {run, true, "shanks", false},
|
|
"nobody runs it": {CheckRunning{}, false, "ace", false},
|
|
"another ask of the same head": {CheckRunning{Head: r.Ref, Trunk: "trunk-0123456789", Builder: "shanks", Build: "build-0"}, true, "ace", false},
|
|
"the same ask at another head": {CheckRunning{Head: "head-other-0000", Trunk: "trunk-0123456789", Builder: "shanks", Build: "build-1"}, true, "ace", false},
|
|
} {
|
|
if got := duplicateOf(c.running, c.found, r, c.me) != ""; got != c.dup {
|
|
t.Errorf("%s: duplicate = %v; want %v", name, got, c.dup)
|
|
}
|
|
}
|
|
}
|