go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/bqutil/storagewrite_test.go (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package bqutil 16 17 import ( 18 "strings" 19 "testing" 20 21 "google.golang.org/protobuf/proto" 22 23 bqpb "go.chromium.org/luci/analysis/proto/bq" 24 25 _ "go.chromium.org/luci/server/tq/txn/spanner" 26 27 . "github.com/smartystreets/goconvey/convey" 28 . "go.chromium.org/luci/common/testing/assertions" 29 ) 30 31 func TestBatch(t *testing.T) { 32 Convey(`Batch`, t, func() { 33 Convey(`Non-empty`, func() { 34 var rows []proto.Message 35 for i := 0; i < 10; i++ { 36 // Rows of ~1 MB each. 37 row := &bqpb.TestVerdictRow{ 38 TestId: strings.Repeat("a", 999950), 39 } 40 So(proto.Size(row), ShouldEqual, 999954) 41 rows = append(rows, row) 42 } 43 44 result, err := batch(rows) 45 So(err, ShouldBeNil) 46 // ~9 MB in the first batch. 47 So(result[0], ShouldHaveLength, 9) 48 // The rest of the rows in the remaining batch. 49 So(result[1], ShouldHaveLength, 1) 50 }) 51 Convey(`Empty`, func() { 52 result, err := batch(nil) 53 So(err, ShouldBeNil) 54 So(result, ShouldHaveLength, 0) 55 }) 56 Convey(`Single row too large`, func() { 57 // 10 MB row. 58 row := &bqpb.TestVerdictRow{ 59 TestId: strings.Repeat("a", 10*1000*1000), 60 } 61 rows := []proto.Message{row} 62 _, err := batch(rows) 63 So(err, ShouldErrLike, "a single row exceeds the maximum BigQuery AppendRows request size of 9000000 bytes") 64 }) 65 }) 66 }