2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-01-28 21:43:48 +00:00
|
|
|
package nomad
|
2016-01-29 23:31:32 +00:00
|
|
|
|
|
|
|
import (
|
2016-01-30 02:18:29 +00:00
|
|
|
"fmt"
|
2016-01-29 23:31:32 +00:00
|
|
|
"testing"
|
2016-01-30 23:55:36 +00:00
|
|
|
"time"
|
2016-01-29 23:31:32 +00:00
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2018-11-07 18:08:23 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2016-01-29 23:31:32 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2016-01-30 02:18:29 +00:00
|
|
|
"github.com/hashicorp/nomad/testutil"
|
2019-06-26 13:55:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-01-29 23:31:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func testBlockedEvals(t *testing.T) (*BlockedEvals, *EvalBroker) {
|
|
|
|
broker := testBroker(t, 0)
|
|
|
|
broker.SetEnabled(true)
|
2018-11-07 18:08:23 +00:00
|
|
|
blocked := NewBlockedEvals(broker, testlog.HCLogger(t))
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked.SetEnabled(true)
|
|
|
|
return blocked, broker
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_Block_Disabled(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
blocked.SetEnabled(false)
|
|
|
|
|
|
|
|
// Create an escaped eval and add it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-01-29 23:31:32 +00:00
|
|
|
e.EscapedComputedClass = true
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block did nothing.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2016-01-29 23:31:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 23:55:36 +00:00
|
|
|
func TestBlockedEvals_Block_SameJob(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-30 23:55:36 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create two blocked evals and add them to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
|
|
|
e2 := mock.BlockedEval()
|
2016-01-30 23:55:36 +00:00
|
|
|
e2.JobID = e.JobID
|
|
|
|
blocked.Block(e)
|
|
|
|
blocked.Block(e2)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block didn't track duplicate.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-30 23:55:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
func TestBlockedEvals_Block_Quota(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create a blocked eval on quota.
|
|
|
|
e := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e.QuotaLimitReached = "foo"
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block did track eval.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(1, blockedStats.TotalQuotaLimit)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
func TestBlockedEvals_Block_PriorUnblocks(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Do unblocks prior to blocking.
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked.Unblock("v1:123", 1000)
|
|
|
|
blocked.Unblock("v1:123", 1001)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create blocked eval with two classes ineligible.
|
|
|
|
e := mock.BlockedEval()
|
2016-05-23 22:24:31 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": false, "v1:456": false}
|
|
|
|
e.SnapshotIndex = 999
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block did track eval.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-05-23 22:24:31 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 23:55:36 +00:00
|
|
|
func TestBlockedEvals_GetDuplicates(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-30 23:55:36 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create duplicate blocked evals and add them to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2018-11-07 18:08:23 +00:00
|
|
|
e.CreateIndex = 100
|
2021-04-29 19:03:45 +00:00
|
|
|
e2 := mock.BlockedEval()
|
2016-01-30 23:55:36 +00:00
|
|
|
e2.JobID = e.JobID
|
2018-11-07 18:08:23 +00:00
|
|
|
e2.CreateIndex = 101
|
2021-04-29 19:03:45 +00:00
|
|
|
e3 := mock.BlockedEval()
|
2016-01-30 23:55:36 +00:00
|
|
|
e3.JobID = e.JobID
|
2018-11-07 18:08:23 +00:00
|
|
|
e3.CreateIndex = 102
|
2021-04-29 19:03:45 +00:00
|
|
|
e4 := mock.BlockedEval()
|
2018-11-07 18:08:23 +00:00
|
|
|
e4.JobID = e.JobID
|
|
|
|
e4.CreateIndex = 100
|
2016-01-30 23:55:36 +00:00
|
|
|
blocked.Block(e)
|
|
|
|
blocked.Block(e2)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify stats such that we are only tracking one.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-30 23:55:36 +00:00
|
|
|
|
|
|
|
// Get the duplicates.
|
|
|
|
out := blocked.GetDuplicates(0)
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Len(out, 1)
|
|
|
|
require.Equal(e, out[0])
|
2016-01-30 23:55:36 +00:00
|
|
|
|
|
|
|
// Call block again after a small sleep.
|
|
|
|
go func() {
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
blocked.Block(e3)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Get the duplicates.
|
|
|
|
out = blocked.GetDuplicates(1 * time.Second)
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Len(out, 1)
|
|
|
|
require.Equal(e2, out[0])
|
2018-11-07 18:08:23 +00:00
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify stats such that we are only tracking one.
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2018-11-13 00:02:23 +00:00
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Add an older evaluation and assert it gets cancelled.
|
2018-11-07 18:08:23 +00:00
|
|
|
blocked.Block(e4)
|
|
|
|
out = blocked.GetDuplicates(0)
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Len(out, 1)
|
|
|
|
require.Equal(e4, out[0])
|
|
|
|
|
|
|
|
// Verify stats such that we are only tracking one.
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-30 23:55:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
func TestBlockedEvals_UnblockEscaped(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create an escaped eval and add it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-01-29 23:31:32 +00:00
|
|
|
e.Status = structs.EvalStatusBlocked
|
|
|
|
e.EscapedComputedClass = true
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be tracked
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(1, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-29 23:31:32 +00:00
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked.Unblock("v1:123", 1000)
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
|
|
|
}
|
2016-01-29 23:31:32 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
func requireBlockedEvalsEnqueued(t *testing.T, blocked *BlockedEvals, broker *EvalBroker, enqueued int) {
|
2016-01-30 02:18:29 +00:00
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
// Verify Unblock caused an enqueue
|
|
|
|
brokerStats := broker.Stats()
|
2019-06-26 13:55:08 +00:00
|
|
|
if brokerStats.TotalReady != enqueued {
|
|
|
|
return false, fmt.Errorf("missing enqueued evals: %#v", brokerStats)
|
2016-01-30 02:18:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Prune old and empty metrics.
|
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
2016-01-30 02:18:29 +00:00
|
|
|
// Verify Unblock updates the stats
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
ok := blockedStats.TotalBlocked == 0 &&
|
|
|
|
blockedStats.TotalEscaped == 0 &&
|
|
|
|
len(blockedStats.BlockedResources.ByJob) == 0
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("evals still blocked: %#v", blockedStats)
|
2016-01-30 02:18:29 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
})
|
2016-01-29 23:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_UnblockEligible(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-01-29 23:31:32 +00:00
|
|
|
e.Status = structs.EvalStatusBlocked
|
2016-01-30 01:46:44 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": true}
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be tracked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
2016-01-29 23:31:32 +00:00
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked.Unblock("v1:123", 1000)
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-01-29 23:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_UnblockIneligible(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create a blocked eval that is ineligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-01-30 01:46:44 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": false}
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be tracked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-29 23:31:32 +00:00
|
|
|
|
|
|
|
// Should do nothing
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked.Unblock("v1:123", 1000)
|
2016-01-29 23:31:32 +00:00
|
|
|
|
2016-01-30 02:18:29 +00:00
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
// Verify Unblock didn't cause an enqueue
|
|
|
|
brokerStats := broker.Stats()
|
|
|
|
if brokerStats.TotalReady != 0 {
|
2021-04-29 19:03:45 +00:00
|
|
|
return false, fmt.Errorf("eval unblocked: %#v", brokerStats)
|
2016-01-30 02:18:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Prune old and empty metrics.
|
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
ok := blockedStats.TotalBlocked == 1 &&
|
|
|
|
blockedStats.TotalEscaped == 0 &&
|
|
|
|
len(blockedStats.BlockedResources.ByJob) == 1
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("eval unblocked: %#v", blockedStats)
|
2016-01-30 02:18:29 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
})
|
2016-01-29 23:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_UnblockUnknown(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create a blocked eval that is ineligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-01-30 01:46:44 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": true, "v1:456": false}
|
2016-01-29 23:31:32 +00:00
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block caused the eval to be tracked.
|
2016-01-29 23:31:32 +00:00
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-01-29 23:31:32 +00:00
|
|
|
|
|
|
|
// Should unblock because the eval hasn't seen this node class.
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked.Unblock("v1:789", 1000)
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-01-29 23:31:32 +00:00
|
|
|
}
|
2016-05-23 22:24:31 +00:00
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
func TestBlockedEvals_UnblockEligible_Quota(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create a blocked eval that is eligible for a particular quota.
|
|
|
|
e := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e.QuotaLimitReached = "foo"
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block caused the eval to be tracked.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(1, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2017-10-13 21:36:02 +00:00
|
|
|
|
|
|
|
blocked.UnblockQuota("foo", 1000)
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_UnblockIneligible_Quota(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create a blocked eval that is eligible on a specific quota.
|
|
|
|
e := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e.QuotaLimitReached = "foo"
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Verify block caused the eval to be tracked.
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(1, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2017-10-13 21:36:02 +00:00
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Should do nothing.
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked.UnblockQuota("bar", 1000)
|
|
|
|
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
// Verify Unblock didn't cause an enqueue
|
|
|
|
brokerStats := broker.Stats()
|
|
|
|
if brokerStats.TotalReady != 0 {
|
2021-04-29 19:03:45 +00:00
|
|
|
return false, fmt.Errorf("eval unblocked: %#v", brokerStats)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Prune old and empty metrics.
|
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
ok := blockedStats.TotalBlocked == 1 &&
|
|
|
|
blockedStats.TotalEscaped == 0 &&
|
|
|
|
blockedStats.TotalQuotaLimit == 1 &&
|
|
|
|
len(blockedStats.BlockedResources.ByJob) == 1
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("eval unblocked: %#v", blockedStats)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-06-24 17:26:13 +00:00
|
|
|
func TestBlockedEvals_Reblock(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-06-24 17:26:13 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create an evaluation, Enqueue/Dequeue it to get a token
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-06-24 17:26:13 +00:00
|
|
|
e.SnapshotIndex = 500
|
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": true, "v1:456": false}
|
|
|
|
broker.Enqueue(e)
|
|
|
|
|
|
|
|
_, token, err := broker.Dequeue([]string{e.Type}, time.Second)
|
2021-04-29 19:03:45 +00:00
|
|
|
require.NoError(err)
|
2016-06-24 17:26:13 +00:00
|
|
|
|
|
|
|
// Reblock the evaluation
|
|
|
|
blocked.Reblock(e, token)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be tracked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-06-24 17:26:13 +00:00
|
|
|
|
|
|
|
// Should unblock because the eval
|
|
|
|
blocked.Unblock("v1:123", 1000)
|
|
|
|
|
|
|
|
brokerStats := broker.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(0, brokerStats.TotalReady)
|
|
|
|
require.Equal(1, brokerStats.TotalUnacked)
|
2016-06-24 17:26:13 +00:00
|
|
|
|
2017-08-07 21:13:05 +00:00
|
|
|
// Ack the evaluation which should cause the reblocked eval to transition
|
2016-06-24 17:26:13 +00:00
|
|
|
// to ready
|
2021-04-29 19:03:45 +00:00
|
|
|
err = broker.Ack(e.ID, token)
|
|
|
|
require.NoError(err)
|
2016-06-24 17:26:13 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-06-24 17:26:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
// Test the block case in which the eval should be immediately unblocked since
|
|
|
|
// it is escaped and old
|
|
|
|
func TestBlockedEvals_Block_ImmediateUnblock_Escaped(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Do an unblock prior to blocking
|
|
|
|
blocked.Unblock("v1:123", 1000)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-05-23 22:24:31 +00:00
|
|
|
e.EscapedComputedClass = true
|
|
|
|
e.SnapshotIndex = 900
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be immediately unblocked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2016-05-23 22:24:31 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-05-23 22:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the block case in which the eval should be immediately unblocked since
|
2016-06-16 23:17:17 +00:00
|
|
|
// there is an unblock on an unseen class that occurred while it was in the
|
2016-06-10 22:48:59 +00:00
|
|
|
// scheduler
|
|
|
|
func TestBlockedEvals_Block_ImmediateUnblock_UnseenClass_After(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Do an unblock prior to blocking
|
|
|
|
blocked.Unblock("v1:123", 1000)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-05-23 22:24:31 +00:00
|
|
|
e.EscapedComputedClass = false
|
|
|
|
e.SnapshotIndex = 900
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be immediately unblocked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2016-05-23 22:24:31 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-05-23 22:24:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 22:48:59 +00:00
|
|
|
// Test the block case in which the eval should not immediately unblock since
|
2016-06-16 23:17:17 +00:00
|
|
|
// there is an unblock on an unseen class that occurred before it was in the
|
2016-06-10 22:48:59 +00:00
|
|
|
// scheduler
|
|
|
|
func TestBlockedEvals_Block_ImmediateUnblock_UnseenClass_Before(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-06-10 22:48:59 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Do an unblock prior to blocking
|
|
|
|
blocked.Unblock("v1:123", 500)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-06-10 22:48:59 +00:00
|
|
|
e.EscapedComputedClass = false
|
|
|
|
e.SnapshotIndex = 900
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be immediately unblocked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-06-10 22:48:59 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
// Test the block case in which the eval should be immediately unblocked since
|
|
|
|
// it a class it is eligible for has been unblocked
|
|
|
|
func TestBlockedEvals_Block_ImmediateUnblock_SeenClass(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-05-23 22:24:31 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Do an unblock prior to blocking
|
|
|
|
blocked.Unblock("v1:123", 1000)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-05-23 22:24:31 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": true, "v1:456": false}
|
|
|
|
e.SnapshotIndex = 900
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be immediately unblocked
|
|
|
|
blockedStats := blocked.Stats()
|
2021-04-29 19:03:45 +00:00
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2016-05-23 22:24:31 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2016-05-23 22:24:31 +00:00
|
|
|
}
|
2016-05-23 23:27:26 +00:00
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
// Test the block case in which the eval should be immediately unblocked since
|
|
|
|
// it a quota has changed that it is using
|
|
|
|
func TestBlockedEvals_Block_ImmediateUnblock_Quota(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Do an unblock prior to blocking
|
|
|
|
blocked.UnblockQuota("my-quota", 1000)
|
|
|
|
|
|
|
|
// Create a blocked eval that is eligible on a specific node class and add
|
|
|
|
// it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e.QuotaLimitReached = "my-quota"
|
|
|
|
e.SnapshotIndex = 900
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block caused the eval to be immediately unblocked
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2017-10-13 21:36:02 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 23:27:26 +00:00
|
|
|
func TestBlockedEvals_UnblockFailed(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2016-05-23 23:27:26 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create blocked evals that are due to failures
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2016-05-23 23:27:26 +00:00
|
|
|
e.TriggeredBy = structs.EvalTriggerMaxPlans
|
|
|
|
e.EscapedComputedClass = true
|
|
|
|
blocked.Block(e)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
e2 := mock.BlockedEval()
|
2016-05-23 23:27:26 +00:00
|
|
|
e2.Status = structs.EvalStatusBlocked
|
|
|
|
e2.TriggeredBy = structs.EvalTriggerMaxPlans
|
|
|
|
e2.ClassEligibility = map[string]bool{"v1:123": true, "v1:456": false}
|
|
|
|
blocked.Block(e2)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
e3 := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e3.TriggeredBy = structs.EvalTriggerMaxPlans
|
|
|
|
e3.QuotaLimitReached = "foo"
|
|
|
|
blocked.Block(e3)
|
|
|
|
|
2016-05-23 23:27:26 +00:00
|
|
|
// Trigger an unblock fail
|
|
|
|
blocked.UnblockFailed()
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Prune old and empty metrics.
|
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
2016-06-23 22:26:26 +00:00
|
|
|
// Verify UnblockFailed caused the eval to be immediately unblocked
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2016-06-23 22:26:26 +00:00
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 3)
|
2016-06-23 22:26:26 +00:00
|
|
|
|
|
|
|
// Reblock an eval for the same job and check that it gets tracked.
|
|
|
|
blocked.Block(e)
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(1, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2016-05-23 23:27:26 +00:00
|
|
|
}
|
2017-01-04 23:25:03 +00:00
|
|
|
|
|
|
|
func TestBlockedEvals_Untrack(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-01-04 23:25:03 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create blocked eval and add to the blocked tracker.
|
|
|
|
e := mock.BlockedEval()
|
2017-01-04 23:25:03 +00:00
|
|
|
e.ClassEligibility = map[string]bool{"v1:123": false, "v1:456": false}
|
|
|
|
e.SnapshotIndex = 1000
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block did track
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2017-01-04 23:25:03 +00:00
|
|
|
|
|
|
|
// Untrack and verify
|
2018-11-07 18:22:08 +00:00
|
|
|
blocked.Untrack(e.JobID, e.Namespace)
|
2021-04-29 19:03:45 +00:00
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2017-01-04 23:25:03 +00:00
|
|
|
}
|
2017-10-13 21:36:02 +00:00
|
|
|
|
|
|
|
func TestBlockedEvals_Untrack_Quota(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
// Create a blocked eval and add it to the blocked tracker.
|
|
|
|
e := mock.BlockedEval()
|
2017-10-13 21:36:02 +00:00
|
|
|
e.QuotaLimitReached = "foo"
|
|
|
|
e.SnapshotIndex = 1000
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block did track
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2017-10-13 21:36:02 +00:00
|
|
|
|
|
|
|
// Untrack and verify
|
2018-11-07 18:22:08 +00:00
|
|
|
blocked.Untrack(e.JobID, e.Namespace)
|
2021-04-29 19:03:45 +00:00
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
2019-06-26 13:55:08 +00:00
|
|
|
|
|
|
|
func TestBlockedEvals_UnblockNode(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
blocked, broker := testBlockedEvals(t)
|
|
|
|
|
|
|
|
require.NotNil(t, broker)
|
|
|
|
|
|
|
|
// Create a blocked evals and add it to the blocked tracker.
|
2021-04-29 19:03:45 +00:00
|
|
|
e := mock.BlockedEval()
|
2019-06-26 13:55:08 +00:00
|
|
|
e.Type = structs.JobTypeSystem
|
|
|
|
e.NodeID = "foo"
|
|
|
|
e.SnapshotIndex = 999
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block did track
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2019-06-26 13:55:08 +00:00
|
|
|
|
|
|
|
blocked.UnblockNode("foo", 1000)
|
|
|
|
requireBlockedEvalsEnqueued(t, blocked, broker, 1)
|
2021-04-29 19:03:45 +00:00
|
|
|
|
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Empty(blocked.system.byNode)
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2019-06-26 13:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockedEvals_SystemUntrack(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2019-06-26 13:55:08 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create a blocked evals and add it to the blocked tracker.
|
|
|
|
e := mock.Eval()
|
|
|
|
e.Type = structs.JobTypeSystem
|
|
|
|
e.NodeID = "foo"
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block did track
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2019-06-26 13:55:08 +00:00
|
|
|
|
|
|
|
// Untrack and verify
|
|
|
|
blocked.Untrack(e.JobID, e.Namespace)
|
2021-04-29 19:03:45 +00:00
|
|
|
blocked.pruneStats(time.Now().UTC())
|
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
2019-06-26 13:55:08 +00:00
|
|
|
}
|
2019-07-17 19:57:10 +00:00
|
|
|
|
|
|
|
func TestBlockedEvals_SystemDisableFlush(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-29 19:03:45 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
2019-07-17 19:57:10 +00:00
|
|
|
blocked, _ := testBlockedEvals(t)
|
|
|
|
|
|
|
|
// Create a blocked evals and add it to the blocked tracker.
|
|
|
|
e := mock.Eval()
|
|
|
|
e.Type = structs.JobTypeSystem
|
|
|
|
e.NodeID = "foo"
|
|
|
|
blocked.Block(e)
|
|
|
|
|
|
|
|
// Verify block did track
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats := blocked.Stats()
|
|
|
|
require.Equal(1, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 1)
|
2019-07-17 19:57:10 +00:00
|
|
|
|
|
|
|
// Disable empties
|
|
|
|
blocked.SetEnabled(false)
|
2021-04-29 19:03:45 +00:00
|
|
|
blockedStats = blocked.Stats()
|
|
|
|
require.Equal(0, blockedStats.TotalBlocked)
|
|
|
|
require.Equal(0, blockedStats.TotalEscaped)
|
|
|
|
require.Equal(0, blockedStats.TotalQuotaLimit)
|
|
|
|
require.Len(blockedStats.BlockedResources.ByJob, 0)
|
|
|
|
require.Empty(blocked.system.evals)
|
|
|
|
require.Empty(blocked.system.byJob)
|
|
|
|
require.Empty(blocked.system.byNode)
|
2019-07-17 19:57:10 +00:00
|
|
|
}
|