1
1
package e2e
2
2
3
3
import (
4
- "context"
5
4
"fmt"
6
5
"net/http"
7
- "slices"
8
6
"testing"
9
- "time"
10
-
11
- "github.com/stretchr/testify/assert"
12
- "github.com/stretchr/testify/require"
13
- "k8s.io/apimachinery/pkg/util/wait"
14
7
15
8
kuberayHTTP "github.com/ray-project/kuberay/apiserver/pkg/http"
16
9
api "github.com/ray-project/kuberay/proto/go_client"
17
10
18
11
rayv1api "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
12
+
13
+ "github.com/stretchr/testify/require"
19
14
)
20
15
21
16
func TestCreateJobWithDisposableClusters (t * testing.T ) {
@@ -94,7 +89,6 @@ func TestCreateJobWithDisposableClusters(t *testing.T) {
94
89
ShutdownAfterJobFinishes : true ,
95
90
ClusterSpec : clusterSpec ,
96
91
TtlSecondsAfterFinished : 60 ,
97
- ActiveDeadlineSeconds : 120 ,
98
92
},
99
93
Namespace : tCtx .GetNamespaceName (),
100
94
},
@@ -113,7 +107,6 @@ func TestCreateJobWithDisposableClusters(t *testing.T) {
113
107
ShutdownAfterJobFinishes : true ,
114
108
ClusterSpec : clusterSpec ,
115
109
TtlSecondsAfterFinished : 60 ,
116
- ActiveDeadlineSeconds : 120 ,
117
110
},
118
111
Namespace : tCtx .GetNamespaceName (),
119
112
},
@@ -223,7 +216,7 @@ func TestCreateJobWithDisposableClusters(t *testing.T) {
223
216
require .NoError (t , err , "No error expected" )
224
217
require .Nil (t , actualRPCStatus , "No RPC status expected" )
225
218
require .NotNil (t , actualJob , "A job is expected" )
226
- waitForRayJob (t , tCtx , tc .Input .Job .Name , []rayv1api.JobStatus {tc .ExpectedJobStatus })
219
+ waitForRayJobInExpectedStatuses (t , tCtx , tc .Input .Job .Name , []rayv1api.JobStatus {tc .ExpectedJobStatus })
227
220
tCtx .DeleteRayJobByName (t , actualJob .Name )
228
221
} else {
229
222
require .EqualError (t , err , tc .ExpectedError .Error (), "Matching error expected" )
@@ -281,7 +274,7 @@ func TestDeleteJob(t *testing.T) {
281
274
if tc .ExpectedError == nil {
282
275
require .NoError (t , err , "No error expected" )
283
276
require .Nil (t , actualRPCStatus , "No RPC status expected" )
284
- waitForDeletedRayJob (t , tCtx , testJobRequest .Job .Name )
277
+ waitForRayJobToDisappear (t , tCtx , testJobRequest .Job .Name )
285
278
} else {
286
279
require .EqualError (t , err , tc .ExpectedError .Error (), "Matching error expected" )
287
280
require .NotNil (t , actualRPCStatus , "A not nill RPC status is required" )
@@ -650,7 +643,7 @@ func TestCreateJobWithClusterSelector(t *testing.T) {
650
643
require .NoError (t , err , "No error expected" )
651
644
require .Nil (t , actualRPCStatus , "No RPC status expected" )
652
645
require .NotNil (t , actualJob , "A job is expected" )
653
- waitForRayJob (t , tCtx , tc .Input .Job .Name , []rayv1api.JobStatus {tc .ExpectedJobStatus })
646
+ waitForRayJobInExpectedStatuses (t , tCtx , tc .Input .Job .Name , []rayv1api.JobStatus {tc .ExpectedJobStatus })
654
647
tCtx .DeleteRayJobByName (t , actualJob .Name )
655
648
} else {
656
649
require .EqualError (t , err , tc .ExpectedError .Error (), "Matching error expected" )
@@ -728,36 +721,6 @@ func createTestJob(t *testing.T, tCtx *End2EndTestingContext, expectedJobStatues
728
721
require .NoError (t , err , "No error expected" )
729
722
require .Nil (t , actualRPCStatus , "No RPC status expected" )
730
723
require .NotNil (t , actualJob , "A job is expected" )
731
- waitForRayJob (t , tCtx , testJobRequest .Job .Name , expectedJobStatues )
724
+ waitForRayJobInExpectedStatuses (t , tCtx , testJobRequest .Job .Name , expectedJobStatues )
732
725
return testJobRequest
733
726
}
734
-
735
- func waitForRayJob (t * testing.T , tCtx * End2EndTestingContext , rayJobName string , expectedJobStatuses []rayv1api.JobStatus ) {
736
- // `expectedJobStatuses` is a slice of job statuses that we expect the job to be in
737
- // wait for the job to be in any of the `expectedJobStatuses` state for 3 minutes
738
- // if is not in that state, return an error
739
- err := wait .PollUntilContextTimeout (tCtx .ctx , 500 * time .Millisecond , 3 * time .Minute , false , func (_ context.Context ) (done bool , err error ) {
740
- rayJob , err := tCtx .GetRayJobByName (rayJobName )
741
- if err != nil {
742
- return true , err
743
- }
744
- t .Logf ("Found ray job with state '%s' for ray job '%s'" , rayJob .Status .JobStatus , rayJobName )
745
- return slices .Contains (expectedJobStatuses , rayJob .Status .JobStatus ), nil
746
- })
747
- require .NoErrorf (t , err , "No error expected when getting status for ray job: '%s', err %v" , rayJobName , err )
748
- }
749
-
750
- func waitForDeletedRayJob (t * testing.T , tCtx * End2EndTestingContext , jobName string ) {
751
- // wait for the job to be deleted
752
- // if is not in that state, return an error
753
- err := wait .PollUntilContextTimeout (tCtx .ctx , 500 * time .Millisecond , 3 * time .Minute , false , func (_ context.Context ) (done bool , err error ) {
754
- rayJob , err := tCtx .GetRayJobByName (jobName )
755
- if err != nil &&
756
- assert .EqualError (t , err , "rayjobs.ray.io \" " + jobName + "\" not found" ) {
757
- return true , nil
758
- }
759
- t .Logf ("Found status of '%s' for ray cluster '%s'" , rayJob .Status .JobStatus , jobName )
760
- return false , err
761
- })
762
- require .NoErrorf (t , err , "No error expected when deleting ray job: '%s', err %v" , jobName , err )
763
- }
0 commit comments