@@ -481,6 +481,97 @@ func TestProvisionerd(t *testing.T) {
481
481
require .NoError (t , closer .Close ())
482
482
})
483
483
484
+ t .Run ("WorkspaceBuildQuotaExceeded" , func (t * testing.T ) {
485
+ t .Parallel ()
486
+ var (
487
+ didComplete atomic.Bool
488
+ didLog atomic.Bool
489
+ didAcquireJob atomic.Bool
490
+ didFail atomic.Bool
491
+ completeChan = make (chan struct {})
492
+ completeOnce sync.Once
493
+ )
494
+
495
+ closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
496
+ return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
497
+ acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
498
+ if ! didAcquireJob .CAS (false , true ) {
499
+ completeOnce .Do (func () { close (completeChan ) })
500
+ return & proto.AcquiredJob {}, nil
501
+ }
502
+
503
+ return & proto.AcquiredJob {
504
+ JobId : "test" ,
505
+ Provisioner : "someprovisioner" ,
506
+ TemplateSourceArchive : createTar (t , map [string ]string {
507
+ "test.txt" : "content" ,
508
+ }),
509
+ Type : & proto.AcquiredJob_WorkspaceBuild_ {
510
+ WorkspaceBuild : & proto.AcquiredJob_WorkspaceBuild {
511
+ Metadata : & sdkproto.Provision_Metadata {},
512
+ },
513
+ },
514
+ }, nil
515
+ },
516
+ updateJob : func (ctx context.Context , update * proto.UpdateJobRequest ) (* proto.UpdateJobResponse , error ) {
517
+ if len (update .Logs ) != 0 {
518
+ didLog .Store (true )
519
+ }
520
+ return & proto.UpdateJobResponse {}, nil
521
+ },
522
+ completeJob : func (ctx context.Context , job * proto.CompletedJob ) (* proto.Empty , error ) {
523
+ didComplete .Store (true )
524
+ return & proto.Empty {}, nil
525
+ },
526
+ commitQuota : func (ctx context.Context , com * proto.CommitQuotaRequest ) (* proto.CommitQuotaResponse , error ) {
527
+ return & proto.CommitQuotaResponse {
528
+ Ok : com .Cost < 20 ,
529
+ }, nil
530
+ },
531
+ failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
532
+ didFail .Store (true )
533
+ return & proto.Empty {}, nil
534
+ },
535
+ }), nil
536
+ }, provisionerd.Provisioners {
537
+ "someprovisioner" : createProvisionerClient (t , provisionerTestServer {
538
+ provision : func (stream sdkproto.DRPCProvisioner_ProvisionStream ) error {
539
+ err := stream .Send (& sdkproto.Provision_Response {
540
+ Type : & sdkproto.Provision_Response_Log {
541
+ Log : & sdkproto.Log {
542
+ Level : sdkproto .LogLevel_DEBUG ,
543
+ Output : "wow" ,
544
+ },
545
+ },
546
+ })
547
+ require .NoError (t , err )
548
+
549
+ err = stream .Send (& sdkproto.Provision_Response {
550
+ Type : & sdkproto.Provision_Response_Complete {
551
+ Complete : & sdkproto.Provision_Complete {
552
+ Resources : []* sdkproto.Resource {
553
+ {
554
+ Cost : 10 ,
555
+ },
556
+ {
557
+ Cost : 15 ,
558
+ },
559
+ },
560
+ },
561
+ },
562
+ })
563
+ require .NoError (t , err )
564
+ return nil
565
+ },
566
+ }),
567
+ })
568
+ require .Condition (t , closedWithin (completeChan , testutil .WaitShort ))
569
+ require .True (t , didLog .Load ())
570
+ require .True (t , didFail .Load ())
571
+ require .False (t , didComplete .Load ())
572
+ require .NoError (t , closer .Close ())
573
+ })
574
+
484
575
t .Run ("WorkspaceBuildFailComplete" , func (t * testing.T ) {
485
576
t .Parallel ()
486
577
var (
@@ -1039,6 +1130,7 @@ func (p *provisionerTestServer) Provision(stream sdkproto.DRPCProvisioner_Provis
1039
1130
// passable functions for dynamic functionality.
1040
1131
type provisionerDaemonTestServer struct {
1041
1132
acquireJob func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error )
1133
+ commitQuota func (ctx context.Context , com * proto.CommitQuotaRequest ) (* proto.CommitQuotaResponse , error )
1042
1134
updateJob func (ctx context.Context , update * proto.UpdateJobRequest ) (* proto.UpdateJobResponse , error )
1043
1135
failJob func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error )
1044
1136
completeJob func (ctx context.Context , job * proto.CompletedJob ) (* proto.Empty , error )
@@ -1047,6 +1139,14 @@ type provisionerDaemonTestServer struct {
1047
1139
func (p * provisionerDaemonTestServer ) AcquireJob (ctx context.Context , empty * proto.Empty ) (* proto.AcquiredJob , error ) {
1048
1140
return p .acquireJob (ctx , empty )
1049
1141
}
1142
+ func (p * provisionerDaemonTestServer ) CommitQuota (ctx context.Context , com * proto.CommitQuotaRequest ) (* proto.CommitQuotaResponse , error ) {
1143
+ if p .commitQuota == nil {
1144
+ return & proto.CommitQuotaResponse {
1145
+ Ok : true ,
1146
+ }, nil
1147
+ }
1148
+ return p .commitQuota (ctx , com )
1149
+ }
1050
1150
1051
1151
func (p * provisionerDaemonTestServer ) UpdateJob (ctx context.Context , update * proto.UpdateJobRequest ) (* proto.UpdateJobResponse , error ) {
1052
1152
return p .updateJob (ctx , update )
0 commit comments