Skip to content

Commit

Permalink
fix de-duplication bug and add test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed May 20, 2020
1 parent 54bde4d commit d2a1a7f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions nomad/csi_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (c *csiBatchRelease) add(vol, namespace string) {
if seen {
return
}
c.seen[id] = struct{}{}

req := structs.CSIVolumeClaimRequest{
VolumeID: vol,
Expand Down
34 changes: 34 additions & 0 deletions nomad/csi_batch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package nomad

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCSI_Batcher(t *testing.T) {
t.Parallel()
srv, shutdown := TestServer(t, func(c *Config) {
c.NumSchedulers = 0 // Prevent automatic dequeue
})
defer shutdown()

batcher := newCSIBatchRelease(srv, nil, 5)

batcher.add("vol0", "global")
batcher.add("vol", "0global")
batcher.add("vol1", "global")
batcher.add("vol1", "global")
batcher.add("vol2", "global")
batcher.add("vol2", "other")
batcher.add("vol3", "global")
batcher.add("vol4", "global")
batcher.add("vol5", "global")
batcher.add("vol6", "global")

require.Len(t, batcher.batches, 2)
require.Len(t, batcher.batches[0].Claims, 5, "first batch")
require.Equal(t, batcher.batches[0].Claims[4].VolumeID, "vol2")
require.Equal(t, batcher.batches[0].Claims[4].Namespace, "other")
require.Len(t, batcher.batches[1].Claims, 4, "second batch")
}

0 comments on commit d2a1a7f

Please sign in to comment.