|
|
|
@ -7,7 +7,6 @@ import (
|
|
|
|
|
"net/url"
|
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@ -108,61 +107,6 @@ func TestListObjectsWithOldTreeNodes(t *testing.T) {
|
|
|
|
|
require.Equal(t, realSize, list.Contents[0].Size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func prepareObjects(hc *handlerContext, bktInfo *data.BucketInfo, prefix string, size int) []string {
|
|
|
|
|
treeID := "version"
|
|
|
|
|
parentID := uint64(0)
|
|
|
|
|
if prefix != "" {
|
|
|
|
|
for _, filename := range strings.Split(prefix, "/") {
|
|
|
|
|
nodeID, err := hc.treeMock.AddNode(hc.Context(), bktInfo, treeID, parentID, map[string]string{
|
|
|
|
|
"FileName": filename,
|
|
|
|
|
})
|
|
|
|
|
require.NoError(hc.t, err)
|
|
|
|
|
parentID = nodeID
|
|
|
|
|
}
|
|
|
|
|
prefix += "/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
objects := make([]string, size)
|
|
|
|
|
|
|
|
|
|
for i := range objects {
|
|
|
|
|
filename := "object" + strconv.Itoa(i)
|
|
|
|
|
filepath := prefix + filename
|
|
|
|
|
|
|
|
|
|
prm := layer.PrmObjectCreate{
|
|
|
|
|
Container: bktInfo.CID,
|
|
|
|
|
Filepath: filepath,
|
|
|
|
|
Payload: nil,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id, err := hc.tp.CreateObject(hc.Context(), prm)
|
|
|
|
|
require.NoError(hc.t, err)
|
|
|
|
|
|
|
|
|
|
newVersion := &data.NodeVersion{
|
|
|
|
|
BaseNodeVersion: data.BaseNodeVersion{
|
|
|
|
|
OID: id,
|
|
|
|
|
ETag: "12345678",
|
|
|
|
|
FilePath: filepath,
|
|
|
|
|
},
|
|
|
|
|
IsUnversioned: true,
|
|
|
|
|
IsCombined: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = hc.treeMock.AddNodeBase(hc.Context(), bktInfo, treeID, parentID, map[string]string{
|
|
|
|
|
"OID": newVersion.OID.EncodeToString(),
|
|
|
|
|
"FileName": filename,
|
|
|
|
|
"IsUnversioned": "true",
|
|
|
|
|
}, false)
|
|
|
|
|
require.NoError(hc.t, err)
|
|
|
|
|
objects[i] = filepath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hc.treeMock.Sort()
|
|
|
|
|
|
|
|
|
|
sort.Strings(objects)
|
|
|
|
|
|
|
|
|
|
return objects
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestListObjectsContextCanceled(t *testing.T) {
|
|
|
|
|
layerCfg := layer.DefaultCachesConfigs(zaptest.NewLogger(t))
|
|
|
|
|
layerCfg.SessionList.Lifetime = time.Hour
|
|
|
|
@ -182,23 +126,23 @@ func TestListObjectsContextCanceled(t *testing.T) {
|
|
|
|
|
// invoke list again to trigger cache eviction
|
|
|
|
|
// (use empty prefix to check that context canceled on replace)
|
|
|
|
|
listObjectsV1(hc, bktName, "", "", "", 2)
|
|
|
|
|
checkContextCanceled(t, session.Context)
|
|
|
|
|
checkContextCanceled(session.Context, t)
|
|
|
|
|
|
|
|
|
|
result2 := listObjectsV2(hc, bktName, "", "", "", "", 2)
|
|
|
|
|
session2 := hc.cache.GetListSession(hc.owner, cache.CreateListSessionCacheKey(bktInfo.CID, "", result2.NextContinuationToken))
|
|
|
|
|
// invoke list again to trigger cache eviction
|
|
|
|
|
// (use non-empty prefix to check that context canceled on cache eviction)
|
|
|
|
|
listObjectsV2(hc, bktName, "o", "", "", "", 2)
|
|
|
|
|
checkContextCanceled(t, session2.Context)
|
|
|
|
|
checkContextCanceled(session2.Context, t)
|
|
|
|
|
|
|
|
|
|
result3 := listObjectsVersions(hc, bktName, "", "", "", "", 2)
|
|
|
|
|
session3 := hc.cache.GetListSession(hc.owner, cache.CreateListSessionCacheKey(bktInfo.CID, "", result3.NextVersionIDMarker))
|
|
|
|
|
// invoke list again to trigger cache eviction
|
|
|
|
|
listObjectsVersions(hc, bktName, "o", "", "", "", 2)
|
|
|
|
|
checkContextCanceled(t, session3.Context)
|
|
|
|
|
checkContextCanceled(session3.Context, t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkContextCanceled(t *testing.T, ctx context.Context) {
|
|
|
|
|
func checkContextCanceled(ctx context.Context, t *testing.T) {
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
case <-time.After(10 * time.Second):
|
|
|
|
|