Skip to content

Improve reliability of KV Store API tests #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions fastly/kv_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,34 @@ import (
"strconv"
"strings"
"testing"
"time"

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

// wait for generation marker of testKey to change
func waitForItemGeneration(t *testing.T, storeID, key string, generation uint64) {
// these API operations are intentionally not wrapped in Record()
require.EventuallyWithT(
t,
func(c *assert.CollectT) {
updatedItem, err := DefaultClient().GetKVStoreItem(&GetKVStoreItemInput{
StoreID: storeID,
Key: key,
})
assert.NoErrorf(c, err, "fetching key %q", key)
assert.NotEqual(c, generation, updatedItem.Generation, "generation marker change")
},
3*time.Second,
1*time.Second,
"updated item is not readable",
)
}

func TestClient_KVStore(t *testing.T) {
// wrapper objects to simplify invocation of functions in the
// 'assert' and 'require' modules
assert := assert.New(t)
require := require.New(t)

Expand Down Expand Up @@ -188,6 +210,8 @@ func TestClient_KVStore(t *testing.T) {
expectedMetadata = "meta"
})

waitForItemGeneration(t, kvStore.StoreID, testKey, item.Generation)

Record(t, "kv_store/get-item-round-2", func(c *Client) {
updatedItem, err := c.GetKVStoreItem(&GetKVStoreItemInput{
StoreID: kvStore.StoreID,
Expand Down Expand Up @@ -229,6 +253,8 @@ func TestClient_KVStore(t *testing.T) {
expectedValue = expectedValue + "suffix"
})

waitForItemGeneration(t, kvStore.StoreID, testKey, item.Generation)

Record(t, "kv_store/get-item-round-3", func(c *Client) {
updatedItem, err := c.GetKVStoreItem(&GetKVStoreItemInput{
StoreID: kvStore.StoreID,
Expand Down
Loading