Skip to content

Commit b97c286

Browse files
authored
fix(storage): No progress report for oneshot write (#12746)
Oneshot writes did not report progress prior to #12422. This fixes them so that they also don't report progress after that. Also add an emulator test, since it turns out our first test of that behavior was in the integration tests!
1 parent e75edd3 commit b97c286

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

storage/client_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,48 @@ func TestOpenWriterEmulated(t *testing.T) {
956956
})
957957
}
958958

959+
func TestWriterOneshotNoProgressReportEmulated(t *testing.T) {
960+
transportClientTest(context.Background(), t, func(t *testing.T, ctx context.Context, project, bucket string, client storageClient) {
961+
_, err := client.CreateBucket(ctx, project, bucket, &BucketAttrs{
962+
Name: bucket,
963+
}, nil)
964+
if err != nil {
965+
t.Fatalf("client.CreateBucket: %v", err)
966+
}
967+
// Oneshot uploads can be forced with either a chunksize of 0, or a
968+
// chunksize larger than the data size.
969+
for _, chunksize := range []int{0, 16 * MiB} {
970+
t.Run(fmt.Sprintf("data size %d chunksize %d", 3*MiB, chunksize), func(t *testing.T) {
971+
prefix := time.Now().Nanosecond()
972+
objName := fmt.Sprintf("%d-object-%d", prefix, time.Now().Nanosecond())
973+
974+
vc := &Client{tc: client}
975+
obj := vc.Bucket(bucket).Object(objName)
976+
w := obj.NewWriter(ctx)
977+
w.ChunkSize = chunksize
978+
progressCalls := 0
979+
w.ProgressFunc = func(int64) { progressCalls++ }
980+
if _, err := w.Write(randomBytes3MiB); err != nil {
981+
t.Fatalf("writer.Write: %v", err)
982+
}
983+
if err := w.Close(); err != nil {
984+
t.Fatalf("writer.Close: %v", err)
985+
}
986+
if progressCalls != 0 {
987+
t.Errorf("ProgressFunc was called %d times, expected 0", progressCalls)
988+
}
989+
attrs, err := obj.Attrs(ctx)
990+
if err != nil {
991+
t.Fatalf("obj.Attrs: %v", err)
992+
}
993+
if attrs.Size != 3*MiB {
994+
t.Errorf("incorrect number of bytes written; got %v, want %v", attrs.Size, 3*MiB)
995+
}
996+
})
997+
}
998+
})
999+
}
1000+
9591001
func TestOpenAppendableWriterEmulated(t *testing.T) {
9601002
transportClientTest(skipHTTP("appends only supported via gRPC"), t, func(t *testing.T, ctx context.Context, project, bucket string, client storageClient) {
9611003
// Populate test data.

storage/grpc_writer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ func (w *gRPCWriter) pickBufferSender() gRPCBidiWriteBufferSender {
320320
return w.newGRPCAppendableObjectBufferSender()
321321
}
322322
if w.forceOneShot {
323-
// One shot semantics
323+
// One shot semantics - no progress reports
324+
w.progress = func(int64) {}
324325
return w.newGRPCOneshotBidiWriteBufferSender()
325326
}
326327
// Resumable write semantics

0 commit comments

Comments
 (0)