@@ -461,3 +461,93 @@ func TestWaitRayClusterProvisioned(t *testing.T) {
461
461
})
462
462
}
463
463
}
464
+
465
+ func TestWaitRayJobDeletionPolicyEnabled (t * testing.T ) {
466
+ tests := []struct {
467
+ name string
468
+ errorMsg string
469
+ startTime time.Time
470
+ events []runtime.Object
471
+ timeout time.Duration
472
+ expectError bool
473
+ }{
474
+ {
475
+ name : "timeout without error" ,
476
+ startTime : time .Now (),
477
+ events : []runtime.Object {},
478
+ timeout : 1 ,
479
+ },
480
+ {
481
+ name : "feature gate error after start time" ,
482
+ startTime : time .Now ().Add (- time .Hour ),
483
+ events : []runtime.Object {
484
+ & corev1.Event {
485
+ ObjectMeta : metav1.ObjectMeta {
486
+ Name : "test-event" ,
487
+ Namespace : "default" ,
488
+ },
489
+ InvolvedObject : corev1.ObjectReference {
490
+ Name : "test-rayjob" ,
491
+ },
492
+ Message : "RayJobDeletionPolicy feature gate must be enabled to use the DeletionPolicy feature" ,
493
+ FirstTimestamp : metav1 .NewTime (time .Now ()),
494
+ LastTimestamp : metav1 .NewTime (time .Now ()),
495
+ },
496
+ },
497
+ expectError : true ,
498
+ errorMsg : "RayJobDeletionPolicy feature gate must be enabled to use the DeletionPolicy feature" ,
499
+ timeout : 5 ,
500
+ },
501
+ {
502
+ name : "feature gate error before start time" ,
503
+ startTime : time .Now (),
504
+ events : []runtime.Object {
505
+ & corev1.Event {
506
+ ObjectMeta : metav1.ObjectMeta {
507
+ Name : "test-event" ,
508
+ Namespace : "default" ,
509
+ },
510
+ InvolvedObject : corev1.ObjectReference {
511
+ Name : "test-rayjob" ,
512
+ },
513
+ Message : "RayJobDeletionPolicy feature gate must be enabled to use the DeletionPolicy feature" ,
514
+ FirstTimestamp : metav1 .NewTime (time .Now ().Add (- time .Hour )),
515
+ LastTimestamp : metav1 .NewTime (time .Now ().Add (- time .Hour )),
516
+ },
517
+ },
518
+ expectError : false ,
519
+ timeout : 1 ,
520
+ },
521
+ }
522
+
523
+ for _ , tc := range tests {
524
+ t .Run (tc .name , func (t * testing.T ) {
525
+ fakeWatcher := watch .NewFake ()
526
+
527
+ // Create a fake clientset; events will be injected via the fakeWatcher
528
+ kubeClientSet := kubeFake .NewSimpleClientset ()
529
+ // Use a reactor to intercept the Watch call for events and return the fakeWatcher
530
+ kubeClientSet .PrependWatchReactor ("events" , func (_ kubetesting.Action ) (bool , watch.Interface , error ) {
531
+ return true , fakeWatcher , nil
532
+ })
533
+
534
+ client := NewClientForTesting (kubeClientSet , nil )
535
+
536
+ if len (tc .events ) > 0 {
537
+ go func () {
538
+ for _ , obj := range tc .events {
539
+ fakeWatcher .Add (obj )
540
+ }
541
+ }()
542
+ }
543
+
544
+ err := client .WaitRayJobDeletionPolicyEnabled (context .Background (), "default" , "test-rayjob" , tc .startTime , tc .timeout )
545
+ if tc .expectError {
546
+ require .Error (t , err )
547
+ assert .Contains (t , err .Error (), tc .errorMsg )
548
+ } else {
549
+ require .NoError (t , err )
550
+ }
551
+ })
552
+ }
553
+ }
0 commit comments