2018-03-10 00:10:38 +00:00
|
|
|
package drainer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDrainer_PartitionAllocDrain(t *testing.T) {
|
2018-04-02 23:40:47 +00:00
|
|
|
t.Parallel()
|
2018-03-10 00:10:38 +00:00
|
|
|
// Set the max ids per reap to something lower.
|
2018-04-02 23:40:47 +00:00
|
|
|
maxIdsPerTxn := 2
|
2018-03-10 00:10:38 +00:00
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
transistions := map[string]*structs.DesiredTransition{"a": nil, "b": nil, "c": nil}
|
|
|
|
evals := []*structs.Evaluation{nil, nil, nil}
|
2018-04-02 23:40:47 +00:00
|
|
|
requests := partitionAllocDrain(maxIdsPerTxn, transistions, evals)
|
2018-03-10 00:10:38 +00:00
|
|
|
require.Len(requests, 3)
|
|
|
|
|
|
|
|
first := requests[0]
|
2018-04-02 23:40:47 +00:00
|
|
|
require.Len(first.Transitions, 2)
|
2018-03-10 00:10:38 +00:00
|
|
|
require.Len(first.Evals, 0)
|
|
|
|
|
|
|
|
second := requests[1]
|
2018-04-02 23:40:47 +00:00
|
|
|
require.Len(second.Transitions, 1)
|
2018-03-10 00:10:38 +00:00
|
|
|
require.Len(second.Evals, 1)
|
|
|
|
|
|
|
|
third := requests[2]
|
2018-04-02 23:40:47 +00:00
|
|
|
require.Len(third.Transitions, 0)
|
2018-03-10 00:10:38 +00:00
|
|
|
require.Len(third.Evals, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDrainer_PartitionIds(t *testing.T) {
|
2018-04-02 23:40:47 +00:00
|
|
|
t.Parallel()
|
2018-03-10 00:10:38 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
// Set the max ids per reap to something lower.
|
2018-04-02 23:40:47 +00:00
|
|
|
maxIdsPerTxn := 2
|
2018-03-10 00:10:38 +00:00
|
|
|
|
|
|
|
ids := []string{"1", "2", "3", "4", "5"}
|
2018-04-02 23:40:47 +00:00
|
|
|
requests := partitionIds(maxIdsPerTxn, ids)
|
2018-03-10 00:10:38 +00:00
|
|
|
require.Len(requests, 3)
|
|
|
|
require.Len(requests[0], 2)
|
|
|
|
require.Len(requests[1], 2)
|
|
|
|
require.Len(requests[2], 1)
|
|
|
|
require.Equal(requests[0][0], ids[0])
|
|
|
|
require.Equal(requests[0][1], ids[1])
|
|
|
|
require.Equal(requests[1][0], ids[2])
|
|
|
|
require.Equal(requests[1][1], ids[3])
|
|
|
|
require.Equal(requests[2][0], ids[4])
|
|
|
|
}
|