@@ -6,6 +6,7 @@ import { expect } from "vitest";
6
6
import { MinimalAuthenticatedEnvironment } from "../../shared/index.js" ;
7
7
import { RunEngine } from "../index.js" ;
8
8
import { setupAuthenticatedEnvironment , setupBackgroundWorker } from "./setup.js" ;
9
+ import { DequeuedMessage } from "@trigger.dev/core/v3" ;
9
10
10
11
vi . setConfig ( { testTimeout : 60_000 } ) ;
11
12
@@ -63,106 +64,115 @@ describe("RunEngine dequeuing", () => {
63
64
expect ( queueLength ) . toBe ( 10 ) ;
64
65
65
66
//dequeue
66
- const dequeued = await engine . dequeueFromMasterQueue ( {
67
- consumerId : "test_12345" ,
68
- masterQueue : "main" ,
69
- maxRunCount : 5 ,
70
- } ) ;
67
+ const dequeued : DequeuedMessage [ ] = [ ] ;
68
+ for ( let i = 0 ; i < 5 ; i ++ ) {
69
+ dequeued . push (
70
+ ...( await engine . dequeueFromMasterQueue ( {
71
+ consumerId : "test_12345" ,
72
+ masterQueue : "main" ,
73
+ maxRunCount : 1 ,
74
+ } ) )
75
+ ) ;
76
+ }
71
77
72
78
expect ( dequeued . length ) . toBe ( 5 ) ;
73
79
} finally {
74
80
engine . quit ( ) ;
75
81
}
76
82
} ) ;
77
83
78
- containerTest ( "Dequeues runs within machine constraints" , async ( { prisma, redisOptions } ) => {
79
- const authenticatedEnvironment = await setupAuthenticatedEnvironment ( prisma , "PRODUCTION" ) ;
84
+ //This will fail until we support dequeuing multiple runs from a single environment
85
+ containerTest . fails (
86
+ "Dequeues runs within machine constraints" ,
87
+ async ( { prisma, redisOptions } ) => {
88
+ const authenticatedEnvironment = await setupAuthenticatedEnvironment ( prisma , "PRODUCTION" ) ;
80
89
81
- const engine = new RunEngine ( {
82
- prisma,
83
- worker : {
84
- redis : redisOptions ,
85
- workers : 1 ,
86
- tasksPerWorker : 10 ,
87
- pollIntervalMs : 100 ,
88
- } ,
89
- queue : {
90
- redis : redisOptions ,
91
- } ,
92
- runLock : {
93
- redis : redisOptions ,
94
- } ,
95
- machines : {
96
- defaultMachine : "small-1x" ,
97
- machines : {
98
- "small-1x" : {
99
- name : "small-1x" as const ,
100
- cpu : 0.5 ,
101
- memory : 0.5 ,
102
- centsPerMs : 0.0001 ,
103
- } ,
104
- } ,
105
- baseCostInCents : 0.0005 ,
106
- } ,
107
- tracer : trace . getTracer ( "test" , "0.0.0" ) ,
108
- } ) ;
109
-
110
- try {
111
- const taskIdentifier = "test-task" ;
112
-
113
- //create background worker
114
- await setupBackgroundWorker ( engine , authenticatedEnvironment , taskIdentifier , {
115
- preset : "small-1x" ,
116
- } ) ;
117
-
118
- //trigger the runs
119
- const runs = await triggerRuns ( {
120
- engine,
121
- environment : authenticatedEnvironment ,
122
- taskIdentifier,
90
+ const engine = new RunEngine ( {
123
91
prisma,
124
- count : 20 ,
125
- } ) ;
126
- expect ( runs . length ) . toBe ( 20 ) ;
127
-
128
- //check the queue length
129
- const queueLength = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
130
- expect ( queueLength ) . toBe ( 20 ) ;
131
-
132
- //dequeue
133
- const dequeued = await engine . dequeueFromMasterQueue ( {
134
- consumerId : "test_12345" ,
135
- masterQueue : "main" ,
136
- maxRunCount : 5 ,
137
- maxResources : {
138
- cpu : 1.1 ,
139
- memory : 3.8 ,
92
+ worker : {
93
+ redis : redisOptions ,
94
+ workers : 1 ,
95
+ tasksPerWorker : 10 ,
96
+ pollIntervalMs : 100 ,
140
97
} ,
141
- } ) ;
142
- expect ( dequeued . length ) . toBe ( 2 ) ;
143
-
144
- //check the queue length
145
- const queueLength2 = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
146
- expect ( queueLength2 ) . toBe ( 18 ) ;
147
-
148
- const dequeued2 = await engine . dequeueFromMasterQueue ( {
149
- consumerId : "test_12345" ,
150
- masterQueue : "main" ,
151
- maxRunCount : 10 ,
152
- maxResources : {
153
- cpu : 4.7 ,
154
- memory : 3.0 ,
98
+ queue : {
99
+ redis : redisOptions ,
100
+ } ,
101
+ runLock : {
102
+ redis : redisOptions ,
103
+ } ,
104
+ machines : {
105
+ defaultMachine : "small-1x" ,
106
+ machines : {
107
+ "small-1x" : {
108
+ name : "small-1x" as const ,
109
+ cpu : 0.5 ,
110
+ memory : 0.5 ,
111
+ centsPerMs : 0.0001 ,
112
+ } ,
113
+ } ,
114
+ baseCostInCents : 0.0005 ,
155
115
} ,
116
+ tracer : trace . getTracer ( "test" , "0.0.0" ) ,
156
117
} ) ;
157
- expect ( dequeued2 . length ) . toBe ( 6 ) ;
158
118
159
- //check the queue length
160
- const queueLength3 = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
161
- expect ( queueLength3 ) . toBe ( 12 ) ;
162
- } finally {
163
- engine . quit ( ) ;
119
+ try {
120
+ const taskIdentifier = "test-task" ;
121
+
122
+ //create background worker
123
+ await setupBackgroundWorker ( engine , authenticatedEnvironment , taskIdentifier , {
124
+ preset : "small-1x" ,
125
+ } ) ;
126
+
127
+ //trigger the runs
128
+ const runs = await triggerRuns ( {
129
+ engine,
130
+ environment : authenticatedEnvironment ,
131
+ taskIdentifier,
132
+ prisma,
133
+ count : 20 ,
134
+ } ) ;
135
+ expect ( runs . length ) . toBe ( 20 ) ;
136
+
137
+ //check the queue length
138
+ const queueLength = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
139
+ expect ( queueLength ) . toBe ( 20 ) ;
140
+
141
+ //dequeue
142
+ const dequeued = await engine . dequeueFromMasterQueue ( {
143
+ consumerId : "test_12345" ,
144
+ masterQueue : "main" ,
145
+ maxRunCount : 5 ,
146
+ maxResources : {
147
+ cpu : 1.1 ,
148
+ memory : 3.8 ,
149
+ } ,
150
+ } ) ;
151
+ expect ( dequeued . length ) . toBe ( 2 ) ;
152
+
153
+ //check the queue length
154
+ const queueLength2 = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
155
+ expect ( queueLength2 ) . toBe ( 18 ) ;
156
+
157
+ const dequeued2 = await engine . dequeueFromMasterQueue ( {
158
+ consumerId : "test_12345" ,
159
+ masterQueue : "main" ,
160
+ maxRunCount : 10 ,
161
+ maxResources : {
162
+ cpu : 4.7 ,
163
+ memory : 3.0 ,
164
+ } ,
165
+ } ) ;
166
+ expect ( dequeued2 . length ) . toBe ( 6 ) ;
167
+
168
+ //check the queue length
169
+ const queueLength3 = await engine . runQueue . lengthOfEnvQueue ( authenticatedEnvironment ) ;
170
+ expect ( queueLength3 ) . toBe ( 12 ) ;
171
+ } finally {
172
+ engine . quit ( ) ;
173
+ }
164
174
}
165
- } ) ;
175
+ ) ;
166
176
} ) ;
167
177
168
178
async function triggerRuns ( {
0 commit comments