(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestRequestPriority(t *testing.T) { |
| 20 | server := setupTestServer(t) |
| 21 | |
| 22 | var recorder requestRecorder |
| 23 | unaryInterceptor, streamInterceptor := recordRequestsInterceptors(&recorder) |
| 24 | opts := []grpc.DialOption{ |
| 25 | grpc.WithInsecure(), |
| 26 | grpc.WithUnaryInterceptor(unaryInterceptor), |
| 27 | grpc.WithStreamInterceptor(streamInterceptor), |
| 28 | } |
| 29 | ctx := context.Background() |
| 30 | conn, err := grpc.DialContext(ctx, server.Addr, opts...) |
| 31 | if err != nil { |
| 32 | t.Fatalf("failed to dial: %v", err) |
| 33 | } |
| 34 | |
| 35 | for _, test := range []struct { |
| 36 | desc string |
| 37 | sessionPriority pb.RequestOptions_Priority |
| 38 | transactionPriority pb.RequestOptions_Priority |
| 39 | want pb.RequestOptions_Priority |
| 40 | }{ |
| 41 | { |
| 42 | desc: "use default MEDIUM priority", |
| 43 | sessionPriority: pb.RequestOptions_PRIORITY_UNSPECIFIED, |
| 44 | transactionPriority: pb.RequestOptions_PRIORITY_UNSPECIFIED, |
| 45 | want: pb.RequestOptions_PRIORITY_MEDIUM, |
| 46 | }, |
| 47 | { |
| 48 | desc: "use session priority", |
| 49 | sessionPriority: pb.RequestOptions_PRIORITY_LOW, |
| 50 | transactionPriority: pb.RequestOptions_PRIORITY_UNSPECIFIED, |
| 51 | want: pb.RequestOptions_PRIORITY_LOW, |
| 52 | }, |
| 53 | { |
| 54 | desc: "use transaction priority", |
| 55 | sessionPriority: pb.RequestOptions_PRIORITY_UNSPECIFIED, |
| 56 | transactionPriority: pb.RequestOptions_PRIORITY_HIGH, |
| 57 | want: pb.RequestOptions_PRIORITY_HIGH, |
| 58 | }, |
| 59 | { |
| 60 | desc: "transaction priority takes over session priority", |
| 61 | sessionPriority: pb.RequestOptions_PRIORITY_HIGH, |
| 62 | transactionPriority: pb.RequestOptions_PRIORITY_LOW, |
| 63 | want: pb.RequestOptions_PRIORITY_LOW, |
| 64 | }, |
| 65 | } { |
| 66 | t.Run(test.desc, func(t *testing.T) { |
| 67 | defer recorder.flush() |
| 68 | |
| 69 | session, err := NewSession("project", "instance", "database", test.sessionPriority, "role", nil, nil, option.WithGRPCConn(conn)) |
| 70 | if err != nil { |
| 71 | t.Fatalf("failed to create spanner-cli session: %v", err) |
| 72 | } |
| 73 | |
| 74 | // Read-Write Transaction. |
| 75 | if err := session.BeginReadWriteTransaction(ctx, pb.TransactionOptions_ISOLATION_LEVEL_UNSPECIFIED, test.transactionPriority, ""); err != nil { |
| 76 | t.Fatalf("failed to begin read write transaction: %v", err) |
nothing calls this directly
no test coverage detected