Skip to content

Commit

Permalink
Upload Test
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Protasio <approtas@amazon.com>
  • Loading branch information
alanprot committed Jul 7, 2022
1 parent 4e219d2 commit f4a04b7
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions pkg/objstore/objstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"io"
"io/ioutil"
"os"
"strings"
"testing"

"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
promtest "github.com/prometheus/client_golang/prometheus/testutil"
"go.uber.org/atomic"

Expand Down Expand Up @@ -93,18 +95,56 @@ func TestTracingReader(t *testing.T) {
testutil.Equals(t, int64(11), size)
}

func TestDownloadDirConcurrency(t *testing.T) {
m := BucketWithMetrics("", NewInMemBucket(), nil)
func TestDownloadUploadDirConcurrency(t *testing.T) {
r := prometheus.NewRegistry()
m := BucketWithMetrics("", NewInMemBucket(), r)
tempDir := t.TempDir()

testutil.Ok(t, m.Upload(context.Background(), "dir/obj1", bytes.NewReader([]byte("1"))))
testutil.Ok(t, m.Upload(context.Background(), "dir/obj2", bytes.NewReader([]byte("2"))))
testutil.Ok(t, m.Upload(context.Background(), "dir/obj3", bytes.NewReader([]byte("3"))))

testutil.Ok(t, promtest.GatherAndCompare(r, strings.NewReader(`
# HELP thanos_objstore_bucket_operations_total Total number of all attempted operations against a bucket.
# TYPE thanos_objstore_bucket_operations_total counter
thanos_objstore_bucket_operations_total{bucket="",operation="attributes"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="delete"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="exists"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="get"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="get_range"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="iter"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="upload"} 3
`), `thanos_objstore_bucket_operations_total`))

testutil.Ok(t, DownloadDir(context.Background(), log.NewNopLogger(), m, "dir/", "dir/", tempDir, WithFetchConcurrency(10)))
i, err := ioutil.ReadDir(tempDir)
testutil.Ok(t, err)
testutil.Assert(t, len(i) == 3)
testutil.Ok(t, promtest.GatherAndCompare(r, strings.NewReader(`
# HELP thanos_objstore_bucket_operations_total Total number of all attempted operations against a bucket.
# TYPE thanos_objstore_bucket_operations_total counter
thanos_objstore_bucket_operations_total{bucket="",operation="attributes"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="delete"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="exists"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="get"} 3
thanos_objstore_bucket_operations_total{bucket="",operation="get_range"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="iter"} 1
thanos_objstore_bucket_operations_total{bucket="",operation="upload"} 3
`), `thanos_objstore_bucket_operations_total`))

testutil.Ok(t, UploadDir(context.Background(), log.NewNopLogger(), m, tempDir, "/dir-copy", WithUploadConcurrency(10)))

testutil.Ok(t, promtest.GatherAndCompare(r, strings.NewReader(`
# HELP thanos_objstore_bucket_operations_total Total number of all attempted operations against a bucket.
# TYPE thanos_objstore_bucket_operations_total counter
thanos_objstore_bucket_operations_total{bucket="",operation="attributes"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="delete"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="exists"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="get"} 3
thanos_objstore_bucket_operations_total{bucket="",operation="get_range"} 0
thanos_objstore_bucket_operations_total{bucket="",operation="iter"} 1
thanos_objstore_bucket_operations_total{bucket="",operation="upload"} 6
`), `thanos_objstore_bucket_operations_total`))
}

func TestTimingTracingReader(t *testing.T) {
Expand Down

0 comments on commit f4a04b7

Please sign in to comment.