github.com/sequix/cortex@v1.1.6/pkg/chunk/aws/dynamodb_storage_client_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/prometheus/common/model"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/sequix/cortex/pkg/chunk/testutils"
    12  )
    13  
    14  const (
    15  	tableName = "table"
    16  )
    17  
    18  func TestChunksPartialError(t *testing.T) {
    19  	fixture := dynamoDBFixture(0, 10, 20)
    20  	defer fixture.Teardown()
    21  	_, client, err := testutils.Setup(fixture, tableName)
    22  	require.NoError(t, err)
    23  
    24  	sc, ok := client.(*dynamoDBStorageClient)
    25  	if !ok {
    26  		t.Error("DynamoDB test client has unexpected type")
    27  		return
    28  	}
    29  	ctx := context.Background()
    30  	// Create more chunks than we can read in one batch
    31  	_, chunks, err := testutils.CreateChunks(0, dynamoDBMaxReadBatchSize+50, model.Now())
    32  	require.NoError(t, err)
    33  	err = client.PutChunks(ctx, chunks)
    34  	require.NoError(t, err)
    35  
    36  	// Make the read fail after 1 success, and keep failing until all retries are exhausted
    37  	sc.setErrorParameters(999, 1)
    38  	// Try to read back all the chunks we created, so we should get an error plus the first batch
    39  	chunksWeGot, err := client.GetChunks(ctx, chunks)
    40  	require.Error(t, err)
    41  	require.Equal(t, dynamoDBMaxReadBatchSize, len(chunksWeGot))
    42  }