diff --git a/internal/common/proto/protoutil.go b/internal/common/proto/protoutil.go index e5cbba39e47..2caaa235f01 100644 --- a/internal/common/proto/protoutil.go +++ b/internal/common/proto/protoutil.go @@ -90,3 +90,10 @@ func ToTimestamp(t time.Time) *types.Timestamp { Nanos: int32(t.Nanosecond()), } } + +func ToStdDuration(pd *types.Duration) time.Duration { + if pd == nil { + return 0 + } + return time.Duration(pd.Seconds)*time.Second + time.Duration(pd.Nanos)*time.Nanosecond +} diff --git a/internal/common/proto/protoutil_test.go b/internal/common/proto/protoutil_test.go index cc6bca52841..6d384f32cb7 100644 --- a/internal/common/proto/protoutil_test.go +++ b/internal/common/proto/protoutil_test.go @@ -105,6 +105,40 @@ func TestToTimestamp(t *testing.T) { } } +func TestToDuration(t *testing.T) { + tests := map[string]struct { + protoDuration *types.Duration + stdDuration time.Duration + }{ + "empty": { + protoDuration: &types.Duration{Seconds: 0, Nanos: 0}, + stdDuration: 0 * time.Second, + }, + "seconds": { + protoDuration: &types.Duration{Seconds: 100, Nanos: 0}, + stdDuration: 100 * time.Second, + }, + "seconds and nanos": { + protoDuration: &types.Duration{Seconds: 100, Nanos: 1000}, + stdDuration: 100*time.Second + 1000*time.Nanosecond, + }, + "negative": { + protoDuration: &types.Duration{Seconds: -100, Nanos: -1000}, + stdDuration: -100*time.Second - 1000*time.Nanosecond, + }, + "nil": { + protoDuration: nil, + stdDuration: 0 * time.Second, + }, + } + types.TimestampNow() + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.stdDuration, ToStdDuration(tc.protoDuration)) + }) + } +} + func utcDate(year, month, day int) time.Time { return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) } diff --git a/internal/testsuite/submitter/submitter.go b/internal/testsuite/submitter/submitter.go index 3160efc23b2..f7b0cc21587 100644 --- a/internal/testsuite/submitter/submitter.go +++ b/internal/testsuite/submitter/submitter.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/armadaproject/armada/internal/common/armadaerrors" + protoutil "github.com/armadaproject/armada/internal/common/proto" "github.com/armadaproject/armada/pkg/api" "github.com/armadaproject/armada/pkg/client" ) @@ -46,7 +47,7 @@ func NewSubmitterFromTestSpec(conn *client.ApiConnectionDetails, testSpec *api.T JobSetName: testSpec.JobSetId, NumBatches: testSpec.NumBatches, BatchSize: testSpec.BatchSize, - Interval: testSpec.Interval, + Interval: protoutil.ToStdDuration(testSpec.Interval), RandomClientId: testSpec.RandomClientId, out: out, } diff --git a/internal/testsuite/testrunner.go b/internal/testsuite/testrunner.go index 92e37ea5668..7f8062248ec 100644 --- a/internal/testsuite/testrunner.go +++ b/internal/testsuite/testrunner.go @@ -12,6 +12,7 @@ import ( "golang.org/x/exp/maps" "golang.org/x/sync/errgroup" + protoutil "github.com/armadaproject/armada/internal/common/proto" "github.com/armadaproject/armada/internal/testsuite/eventbenchmark" "github.com/armadaproject/armada/internal/testsuite/eventlogger" "github.com/armadaproject/armada/internal/testsuite/eventsplitter" @@ -67,8 +68,9 @@ func (srv *TestRunner) Run(ctx context.Context) (err error) { // Optional timeout var cancel context.CancelFunc - if srv.testSpec.Timeout != 0 { - ctx, cancel = context.WithTimeout(ctx, srv.testSpec.Timeout) + timeout := protoutil.ToStdDuration(srv.testSpec.Timeout) + if timeout != 0 { + ctx, cancel = context.WithTimeout(ctx, timeout) } else { ctx, cancel = context.WithCancel(ctx) } diff --git a/pkg/api/testspec.pb.go b/pkg/api/testspec.pb.go index ab9307f5034..289ec2f8389 100644 --- a/pkg/api/testspec.pb.go +++ b/pkg/api/testspec.pb.go @@ -8,21 +8,15 @@ import ( io "io" math "math" math_bits "math/bits" - reflect "reflect" - strings "strings" - time "time" - _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + types "github.com/gogo/protobuf/types" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -83,9 +77,9 @@ type TestSpec struct { BatchSize uint32 `protobuf:"varint,6,opt,name=batch_size,json=batchSize,proto3" json:"batchSize,omitempty"` // Time between batches. // If 0, jobs are submitted as quickly as possible. - Interval time.Duration `protobuf:"bytes,7,opt,name=interval,proto3,stdduration" json:"interval"` + Interval *types.Duration `protobuf:"bytes,7,opt,name=interval,proto3" json:"interval,omitempty"` // Number of seconds to wait for jobs to finish. - Timeout time.Duration `protobuf:"bytes,8,opt,name=timeout,proto3,stdduration" json:"timeout"` + Timeout *types.Duration `protobuf:"bytes,8,opt,name=timeout,proto3" json:"timeout,omitempty"` Cancel TestSpec_Cancel `protobuf:"varint,9,opt,name=cancel,proto3,enum=api.TestSpec_Cancel" json:"cancel,omitempty"` // Test name. Defaults to the filename if not provided. Name string `protobuf:"bytes,10,opt,name=name,proto3" json:"name,omitempty"` @@ -99,8 +93,9 @@ type TestSpec struct { Target string `protobuf:"bytes,14,opt,name=target,proto3" json:"target,omitempty"` } -func (m *TestSpec) Reset() { *m = TestSpec{} } -func (*TestSpec) ProtoMessage() {} +func (m *TestSpec) Reset() { *m = TestSpec{} } +func (m *TestSpec) String() string { return proto.CompactTextString(m) } +func (*TestSpec) ProtoMessage() {} func (*TestSpec) Descriptor() ([]byte, []int) { return fileDescriptor_38d601305b414287, []int{0} } @@ -173,18 +168,18 @@ func (m *TestSpec) GetBatchSize() uint32 { return 0 } -func (m *TestSpec) GetInterval() time.Duration { +func (m *TestSpec) GetInterval() *types.Duration { if m != nil { return m.Interval } - return 0 + return nil } -func (m *TestSpec) GetTimeout() time.Duration { +func (m *TestSpec) GetTimeout() *types.Duration { if m != nil { return m.Timeout } - return 0 + return nil } func (m *TestSpec) GetCancel() TestSpec_Cancel { @@ -237,50 +232,48 @@ func init() { func init() { proto.RegisterFile("pkg/api/testspec.proto", fileDescriptor_38d601305b414287) } var fileDescriptor_38d601305b414287 = []byte{ - // 683 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x94, 0xcf, 0x4e, 0xdb, 0x40, - 0x10, 0xc6, 0xe3, 0x04, 0x9c, 0x64, 0x53, 0x42, 0xd8, 0x04, 0xba, 0xa0, 0xca, 0x8e, 0x38, 0xb4, - 0xa9, 0x44, 0x9d, 0x0a, 0xaa, 0x4a, 0x55, 0x4f, 0x18, 0xa8, 0x9a, 0xfe, 0x17, 0xe1, 0x50, 0x7a, - 0x71, 0x6d, 0x67, 0x6a, 0x36, 0x8d, 0xbd, 0xc6, 0x5e, 0xa3, 0x96, 0x53, 0x1f, 0xa1, 0x47, 0x9e, - 0xa1, 0x4f, 0xc2, 0x91, 0x23, 0x27, 0xb7, 0x0d, 0x37, 0x3f, 0x45, 0x95, 0xb5, 0x0d, 0xe6, 0xd4, - 0xdb, 0xce, 0x6f, 0xbe, 0x6f, 0x76, 0x33, 0x33, 0x31, 0x5a, 0xf1, 0xbf, 0x3a, 0x7d, 0xd3, 0xa7, - 0x7d, 0x0e, 0x21, 0x0f, 0x7d, 0xb0, 0x35, 0x3f, 0x60, 0x9c, 0xe1, 0x8a, 0xe9, 0xd3, 0x35, 0xc5, - 0x61, 0xcc, 0x99, 0x40, 0x5f, 0x20, 0x2b, 0xfa, 0xd2, 0x1f, 0x45, 0x81, 0xc9, 0x29, 0xf3, 0x52, - 0xd1, 0xda, 0x23, 0x87, 0xf2, 0xa3, 0xc8, 0xd2, 0x6c, 0xe6, 0xf6, 0x1d, 0xe6, 0xb0, 0x1b, 0xe1, - 0x2c, 0x12, 0x81, 0x38, 0x65, 0xf2, 0x4e, 0x7e, 0x57, 0x18, 0x59, 0x2e, 0xe5, 0x19, 0x6d, 0xe7, - 0x14, 0x4e, 0xc0, 0xcb, 0xe0, 0xfa, 0x59, 0x15, 0xd5, 0x0e, 0x20, 0xe4, 0x43, 0x1f, 0x6c, 0xbc, - 0x8d, 0xe6, 0xc6, 0xcc, 0x0a, 0x89, 0xd4, 0xad, 0xf4, 0x1a, 0x9b, 0xab, 0x9a, 0xe9, 0x53, 0xed, - 0x15, 0xb3, 0x86, 0xa2, 0xca, 0x3e, 0x1c, 0x47, 0x10, 0xf2, 0x01, 0x07, 0x57, 0xc7, 0x49, 0xac, - 0x36, 0x67, 0xd2, 0x0d, 0xe6, 0x52, 0x0e, 0xae, 0xcf, 0xbf, 0xef, 0x0b, 0x2b, 0xfe, 0x88, 0x16, - 0xe1, 0x9b, 0x0f, 0x36, 0x87, 0x91, 0x21, 0xee, 0x09, 0x49, 0x59, 0x54, 0x5b, 0x12, 0xd5, 0xf6, - 0x66, 0xe8, 0x2d, 0x84, 0xa1, 0xe9, 0x80, 0x7e, 0x2f, 0x89, 0x55, 0x92, 0xab, 0x45, 0xa6, 0x58, - 0xaf, 0x79, 0x3b, 0x83, 0x1f, 0xa2, 0xf9, 0xe3, 0x08, 0x22, 0x20, 0x95, 0xae, 0xd4, 0xab, 0xeb, - 0xed, 0x24, 0x56, 0x17, 0x05, 0x28, 0x78, 0x52, 0x05, 0x7e, 0x82, 0xd0, 0x98, 0x59, 0x46, 0x08, - 0xdc, 0xa0, 0x23, 0x32, 0x27, 0xf4, 0x2b, 0x49, 0xac, 0xe2, 0x31, 0xb3, 0x86, 0xc0, 0x07, 0xa3, - 0x82, 0xa5, 0x96, 0x33, 0xfc, 0x0c, 0x35, 0xbc, 0xc8, 0x35, 0x2c, 0x93, 0xdb, 0x47, 0x10, 0x92, - 0xf9, 0xae, 0xd4, 0x5b, 0xd0, 0x49, 0x12, 0xab, 0x1d, 0x2f, 0x72, 0xf5, 0x94, 0x16, 0x8c, 0xe8, - 0x86, 0xe2, 0xa7, 0x08, 0x09, 0x9b, 0x11, 0xd2, 0x53, 0x20, 0xb2, 0x70, 0xde, 0x4d, 0x62, 0xb5, - 0x2d, 0xe8, 0x90, 0x9e, 0x16, 0x1f, 0x59, 0xbf, 0x86, 0xf8, 0x35, 0xaa, 0x51, 0x8f, 0x43, 0x70, - 0x62, 0x4e, 0x48, 0xb5, 0x2b, 0x89, 0xa6, 0xa7, 0xab, 0xa0, 0xe5, 0x13, 0xd6, 0x76, 0xb3, 0x55, - 0xd0, 0x3b, 0xe7, 0xb1, 0x5a, 0x4a, 0x62, 0xf5, 0xda, 0x72, 0xf6, 0x5b, 0x95, 0xf6, 0xaf, 0x23, - 0xfc, 0x12, 0x55, 0x39, 0x75, 0x81, 0x45, 0x9c, 0xd4, 0xfe, 0x57, 0xab, 0x9d, 0xd5, 0xca, 0x1d, - 0xa2, 0x54, 0x1e, 0x60, 0x1d, 0xc9, 0xb6, 0xe9, 0xd9, 0x30, 0x21, 0xf5, 0xae, 0xd4, 0x6b, 0x6e, - 0x76, 0xc4, 0xec, 0xf2, 0x35, 0xd1, 0x76, 0x44, 0x4e, 0xef, 0x24, 0xb1, 0xda, 0x4a, 0x75, 0x85, - 0x5f, 0x97, 0x39, 0xf1, 0x7d, 0x34, 0xe7, 0x99, 0x2e, 0x10, 0x24, 0xba, 0x2f, 0x16, 0x66, 0x16, - 0x17, 0x17, 0x66, 0x16, 0xe3, 0x17, 0xa8, 0x15, 0x98, 0xde, 0x88, 0xb9, 0x86, 0x3d, 0xa1, 0xe0, - 0x89, 0x89, 0x35, 0xba, 0x52, 0xaf, 0x96, 0xae, 0x47, 0x9a, 0xdb, 0x11, 0xa9, 0x5b, 0x73, 0x6b, - 0xde, 0xce, 0xe0, 0xc7, 0xa8, 0xe6, 0x00, 0x37, 0x26, 0xcc, 0x09, 0xc9, 0x1d, 0xe1, 0x5f, 0x4e, - 0x62, 0x75, 0xc9, 0x01, 0xfe, 0x86, 0x39, 0xc5, 0xb9, 0x55, 0x33, 0x84, 0x9f, 0xa3, 0x06, 0x78, - 0x27, 0x34, 0x60, 0x9e, 0x0b, 0x1e, 0x27, 0x0b, 0xe2, 0xa1, 0xab, 0x49, 0xac, 0x2e, 0x17, 0x70, - 0xc1, 0x58, 0x54, 0xe3, 0x0d, 0x24, 0x73, 0x33, 0x70, 0x80, 0x93, 0xa6, 0xf0, 0x89, 0x66, 0xa4, - 0xa4, 0xd8, 0x8c, 0x94, 0xac, 0x6f, 0x21, 0x39, 0x6d, 0x1a, 0x96, 0x51, 0xf9, 0xdd, 0xfb, 0x56, - 0x09, 0xd7, 0xd1, 0xbc, 0x7e, 0x68, 0x0c, 0x76, 0x5b, 0x12, 0x46, 0x48, 0xd6, 0x0f, 0x8d, 0xe1, - 0xde, 0x41, 0xab, 0x9c, 0x9d, 0x07, 0xbb, 0xc3, 0x56, 0x45, 0xff, 0x7c, 0xf9, 0x57, 0x29, 0xfd, - 0x98, 0x2a, 0xd2, 0xf9, 0x54, 0x91, 0x2e, 0xa6, 0x8a, 0xf4, 0x67, 0xaa, 0x48, 0x3f, 0xaf, 0x94, - 0xd2, 0xc5, 0x95, 0x52, 0xba, 0xbc, 0x52, 0x4a, 0x9f, 0x1e, 0x14, 0x3e, 0x0b, 0x66, 0xe0, 0x9a, - 0x23, 0xd3, 0x0f, 0xd8, 0x18, 0x6c, 0x9e, 0x45, 0xfd, 0xec, 0x1f, 0xff, 0xab, 0xdc, 0xd9, 0x16, - 0xe0, 0x43, 0x9a, 0xd6, 0x06, 0x4c, 0xdb, 0xf6, 0xa9, 0x25, 0x8b, 0xc5, 0xd8, 0xfa, 0x17, 0x00, - 0x00, 0xff, 0xff, 0x6e, 0x14, 0xc2, 0x91, 0x9c, 0x04, 0x00, 0x00, + // 652 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0xc1, 0x4e, 0xdb, 0x4a, + 0x14, 0x86, 0xe3, 0x04, 0x9c, 0x64, 0x72, 0x09, 0x61, 0x08, 0xdc, 0x01, 0x5d, 0xd9, 0x11, 0x8b, + 0x7b, 0x73, 0x25, 0xe4, 0x54, 0x50, 0x55, 0xaa, 0xba, 0xc2, 0x40, 0xa5, 0xa0, 0xd2, 0x56, 0x84, + 0x05, 0x74, 0x63, 0x8d, 0x9d, 0x53, 0x33, 0x69, 0xec, 0x31, 0xf6, 0x18, 0xb5, 0x3c, 0x45, 0x1f, + 0xa0, 0x4f, 0xd0, 0x27, 0xe9, 0x92, 0x65, 0x57, 0x56, 0x05, 0x3b, 0x3f, 0x45, 0x95, 0xb1, 0xdd, + 0x0e, 0xab, 0xee, 0x32, 0xdf, 0xf9, 0xff, 0x93, 0x99, 0xf3, 0x1f, 0xa3, 0xcd, 0xe8, 0x83, 0x3f, + 0xa2, 0x11, 0x1b, 0x09, 0x48, 0x44, 0x12, 0x81, 0x67, 0x45, 0x31, 0x17, 0x1c, 0x37, 0x68, 0xc4, + 0xb6, 0x0d, 0x9f, 0x73, 0x7f, 0x0e, 0x23, 0x89, 0xdc, 0xf4, 0xfd, 0x68, 0x9a, 0xc6, 0x54, 0x30, + 0x1e, 0x16, 0xa2, 0xed, 0x7e, 0x65, 0x4e, 0x52, 0x37, 0x60, 0xa2, 0xa4, 0xeb, 0x15, 0x85, 0x1b, + 0x08, 0x4b, 0xb8, 0xf3, 0xa5, 0x89, 0x5a, 0xe7, 0x90, 0x88, 0x49, 0x04, 0x1e, 0x3e, 0x40, 0x4b, + 0x33, 0xee, 0x26, 0x44, 0x1b, 0x34, 0x86, 0x9d, 0xbd, 0x2d, 0x8b, 0x46, 0xcc, 0x3a, 0xe1, 0xee, + 0x44, 0x76, 0x39, 0x83, 0xeb, 0x14, 0x12, 0x31, 0x16, 0x10, 0xd8, 0x38, 0xcf, 0xcc, 0xee, 0x42, + 0xba, 0xcb, 0x03, 0x26, 0x20, 0x88, 0xc4, 0xa7, 0x33, 0x69, 0xc5, 0x17, 0x68, 0x15, 0x3e, 0x46, + 0xe0, 0x09, 0x98, 0x3a, 0xf2, 0x7f, 0x12, 0x52, 0x97, 0xdd, 0xd6, 0x64, 0xb7, 0xe3, 0x05, 0x3a, + 0x85, 0x24, 0xa1, 0x3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0x18, 0xb5, + 0xef, 0x0f, 0x46, 0xed, 0xdd, 0x7f, 0x3e, 0x13, 0x57, 0xa9, 0x6b, 0x79, 0x3c, 0x18, 0xd1, 0x38, + 0xa0, 0x53, 0x1a, 0xc5, 0x7c, 0x06, 0x9e, 0x28, 0x4f, 0xa3, 0xf2, 0x6b, 0xff, 0x5a, 0xef, 0x1f, + 0x48, 0xf0, 0xb6, 0x28, 0x5b, 0x63, 0x6e, 0x1d, 0x44, 0xcc, 0xd5, 0xe5, 0x4a, 0xec, 0xff, 0x0c, + 0x00, 0x00, 0xff, 0xff, 0xa5, 0x42, 0x8d, 0x1f, 0x69, 0x04, 0x00, 0x00, } func (m *TestSpec) Marshal() (dAtA []byte, err error) { @@ -349,22 +342,30 @@ func (m *TestSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x48 } - n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.Timeout, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.Timeout):]) - if err1 != nil { - return 0, err1 + if m.Timeout != nil { + { + size, err := m.Timeout.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTestspec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 } - i -= n1 - i = encodeVarintTestspec(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x42 - n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.Interval, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.Interval):]) - if err2 != nil { - return 0, err2 + if m.Interval != nil { + { + size, err := m.Interval.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTestspec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a } - i -= n2 - i = encodeVarintTestspec(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0x3a if m.BatchSize != 0 { i = encodeVarintTestspec(dAtA, i, uint64(m.BatchSize)) i-- @@ -463,10 +464,14 @@ func (m *TestSpec) Size() (n int) { if m.BatchSize != 0 { n += 1 + sovTestspec(uint64(m.BatchSize)) } - l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.Interval) - n += 1 + l + sovTestspec(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.Timeout) - n += 1 + l + sovTestspec(uint64(l)) + if m.Interval != nil { + l = m.Interval.Size() + n += 1 + l + sovTestspec(uint64(l)) + } + if m.Timeout != nil { + l = m.Timeout.Size() + n += 1 + l + sovTestspec(uint64(l)) + } if m.Cancel != 0 { n += 1 + sovTestspec(uint64(m.Cancel)) } @@ -497,47 +502,6 @@ func sovTestspec(x uint64) (n int) { func sozTestspec(x uint64) (n int) { return sovTestspec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *TestSpec) String() string { - if this == nil { - return "nil" - } - repeatedStringForJobs := "[]*JobSubmitRequestItem{" - for _, f := range this.Jobs { - repeatedStringForJobs += strings.Replace(fmt.Sprintf("%v", f), "JobSubmitRequestItem", "JobSubmitRequestItem", 1) + "," - } - repeatedStringForJobs += "}" - repeatedStringForExpectedEvents := "[]*EventMessage{" - for _, f := range this.ExpectedEvents { - repeatedStringForExpectedEvents += strings.Replace(fmt.Sprintf("%v", f), "EventMessage", "EventMessage", 1) + "," - } - repeatedStringForExpectedEvents += "}" - s := strings.Join([]string{`&TestSpec{`, - `Jobs:` + repeatedStringForJobs + `,`, - `ExpectedEvents:` + repeatedStringForExpectedEvents + `,`, - `Queue:` + fmt.Sprintf("%v", this.Queue) + `,`, - `JobSetId:` + fmt.Sprintf("%v", this.JobSetId) + `,`, - `NumBatches:` + fmt.Sprintf("%v", this.NumBatches) + `,`, - `BatchSize:` + fmt.Sprintf("%v", this.BatchSize) + `,`, - `Interval:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Interval), "Duration", "types.Duration", 1), `&`, ``, 1) + `,`, - `Timeout:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timeout), "Duration", "types.Duration", 1), `&`, ``, 1) + `,`, - `Cancel:` + fmt.Sprintf("%v", this.Cancel) + `,`, - `Name:` + fmt.Sprintf("%v", this.Name) + `,`, - `RandomClientId:` + fmt.Sprintf("%v", this.RandomClientId) + `,`, - `GetLogs:` + fmt.Sprintf("%v", this.GetLogs) + `,`, - `Environment:` + fmt.Sprintf("%v", this.Environment) + `,`, - `Target:` + fmt.Sprintf("%v", this.Target) + `,`, - `}`, - }, "") - return s -} -func valueToStringTestspec(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} func (m *TestSpec) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -766,7 +730,10 @@ func (m *TestSpec) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.Interval, dAtA[iNdEx:postIndex]); err != nil { + if m.Interval == nil { + m.Interval = &types.Duration{} + } + if err := m.Interval.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -799,7 +766,10 @@ func (m *TestSpec) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.Timeout, dAtA[iNdEx:postIndex]); err != nil { + if m.Timeout == nil { + m.Timeout = &types.Duration{} + } + if err := m.Timeout.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/pkg/api/testspec.proto b/pkg/api/testspec.proto index 64e8ff5264b..afa616bdd7c 100644 --- a/pkg/api/testspec.proto +++ b/pkg/api/testspec.proto @@ -5,13 +5,9 @@ option go_package = "github.com/armadaproject/armada/pkg/api"; option csharp_namespace = "ArmadaProject.Io.Api"; import "google/protobuf/duration.proto"; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "pkg/api/submit.proto"; import "pkg/api/event.proto"; -option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.stringer_all) = true; - // Defines a test case for the Armada test suite. // Defined as a proto message to enable unmarshalling oneof fields. message TestSpec { @@ -33,9 +29,9 @@ message TestSpec { uint32 batch_size = 6; // Time between batches. // If 0, jobs are submitted as quickly as possible. - google.protobuf.Duration interval = 7 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration interval = 7; // Number of seconds to wait for jobs to finish. - google.protobuf.Duration timeout = 8 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; + google.protobuf.Duration timeout = 8; // If the jobs in this spec. should be cancelled. enum Cancel { NO = 0; // Do not cancel jobs. @@ -54,4 +50,4 @@ message TestSpec { string environment = 13; // Value of the target label set on exported Prometheus metrics. string target = 14; -} \ No newline at end of file +} diff --git a/pkg/executorapi/util.go b/pkg/executorapi/util.go index 751ec123932..e6180575a16 100644 --- a/pkg/executorapi/util.go +++ b/pkg/executorapi/util.go @@ -3,15 +3,13 @@ package executorapi import ( "time" + "github.com/pkg/errors" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + "github.com/armadaproject/armada/internal/common/armadaerrors" armadamaps "github.com/armadaproject/armada/internal/common/maps" armadaslices "github.com/armadaproject/armada/internal/common/slices" - - "github.com/pkg/errors" - - "github.com/armadaproject/armada/internal/common/armadaerrors" "github.com/armadaproject/armada/internal/scheduler/schedulerobjects" "github.com/armadaproject/armada/pkg/api" ) diff --git a/pkg/executorapi/util_test.go b/pkg/executorapi/util_test.go new file mode 100644 index 00000000000..aea8181cbe5 --- /dev/null +++ b/pkg/executorapi/util_test.go @@ -0,0 +1,48 @@ +package executorapi + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/api/resource" + + "github.com/armadaproject/armada/internal/scheduler/schedulerobjects" +) + +func TestComputeResourceFromProtoResources(t *testing.T) { + oneCpu := resource.MustParse("1") + oneGi := resource.MustParse("1Gi") + + input := map[string]resource.Quantity{ + "cpu": resource.MustParse("1"), + "memory": resource.MustParse("1Gi"), + } + + expected := &ComputeResource{ + Resources: map[string]*resource.Quantity{ + "cpu": &oneCpu, + "memory": &oneGi, + }, + } + actual := ComputeResourceFromProtoResources(input) + assert.Equal(t, actual, expected) +} + +func TestResourceListFromProtoResources(t *testing.T) { + oneCpu := resource.MustParse("1") + oneGi := resource.MustParse("1Gi") + + input := map[string]*resource.Quantity{ + "cpu": &oneCpu, + "memory": &oneGi, + } + expected := schedulerobjects.ResourceList{ + Resources: map[string]resource.Quantity{ + "cpu": resource.MustParse("1"), + "memory": resource.MustParse("1Gi"), + }, + } + + actual := ResourceListFromProtoResources(input) + assert.Equal(t, actual, expected) +}