@@ -2529,6 +2529,47 @@ func TestWriterChunkTransferTimeoutEmulated(t *testing.T) {
2529
2529
})
2530
2530
}
2531
2531
2532
+ func TestWriterChunkBufferReuseEmulated (t * testing.T ) {
2533
+ transportClientTest (context .Background (), t , func (t * testing.T , ctx context.Context , project , bucket string , client storageClient ) {
2534
+ c := & Client {tc : client }
2535
+ if err := c .Bucket (bucket ).Create (ctx , project , & BucketAttrs {}); err != nil {
2536
+ t .Fatalf ("creating bucket: %v" , err )
2537
+ }
2538
+ objName := fmt .Sprintf ("object-%d" , time .Now ().Nanosecond ())
2539
+ w := c .Bucket (bucket ).Object (objName ).NewWriter (ctx )
2540
+ const chunkSize = 32 * 1024 * 1024
2541
+ w .ChunkSize = chunkSize
2542
+
2543
+ // Write twice using the same buffer, then clear it.
2544
+ buf := bytes .Repeat ([]byte ("A" ), chunkSize )
2545
+ if n , err := w .Write (buf ); err != nil || n != chunkSize {
2546
+ t .Errorf ("failed first write: wrote %v, want %v, err %v" , n , chunkSize , err )
2547
+ }
2548
+ copy (buf , bytes .Repeat ([]byte ("B" ), chunkSize ))
2549
+ if n , err := w .Write (buf ); err != nil || n != chunkSize {
2550
+ t .Errorf ("failed second write: wrote %v, want %v, err %v" , n , chunkSize , err )
2551
+ }
2552
+ clear (buf )
2553
+ if err := w .Close (); err != nil {
2554
+ t .Errorf ("failed close: %v" , err )
2555
+ }
2556
+
2557
+ r , err := c .Bucket (bucket ).Object (objName ).NewReader (ctx )
2558
+ if err != nil {
2559
+ t .Fatalf ("opening reading: %v" , err )
2560
+ }
2561
+ defer r .Close ()
2562
+ want := append (bytes .Repeat ([]byte ("A" ), chunkSize ), bytes .Repeat ([]byte ("B" ), chunkSize )... )
2563
+ got , err := io .ReadAll (r )
2564
+ if err != nil {
2565
+ t .Fatalf ("reading object: %v" , err )
2566
+ }
2567
+ if ! bytes .Equal (got , want ) {
2568
+ t .Errorf ("content does not match, got len %v, want len %v" , len (got ), len (want ))
2569
+ }
2570
+ })
2571
+ }
2572
+
2532
2573
func TestWriterChunkRetryDeadlineEmulated (t * testing.T ) {
2533
2574
transportClientTest (context .Background (), t , func (t * testing.T , ctx context.Context , project , bucket string , client storageClient ) {
2534
2575
const (
0 commit comments