-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follows similar pattern to recently added `throttle` The integration test timing could lead to flakes but I tried to leave a generous buffer to minimize this without making the test too long. I wanted to add a second integration test for the debounce `timeout`, but configuring debounce with a `timeout` seems to result in the function never getting executed on the latest dev server (0.29.6). I verified this is true with the JS SDK as well.
- Loading branch information
1 parent
0fc1ebf
commit b1d9daf
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...g-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/DebouncedFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.inngest.springbootdemo.testfunctions; | ||
|
||
import com.inngest.FunctionContext; | ||
import com.inngest.InngestFunction; | ||
import com.inngest.InngestFunctionConfigBuilder; | ||
import com.inngest.Step; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.Duration; | ||
|
||
public class DebouncedFunction extends InngestFunction { | ||
|
||
@NotNull | ||
@Override | ||
public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { | ||
return builder | ||
.id("DebouncedFunction") | ||
.name("Debounced Function") | ||
.triggerEvent("test/debounced_2_second") | ||
.debounce(Duration.ofSeconds(2)); | ||
} | ||
|
||
private static int answer = 42; | ||
|
||
@Override | ||
public Integer execute(FunctionContext ctx, Step step) { | ||
return step.run("result", () -> answer++, Integer.class); | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...-boot-demo/src/test/java/com/inngest/springbootdemo/DebouncedFunctionIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
import com.inngest.Inngest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.api.parallel.ExecutionMode; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@IntegrationTest | ||
@Execution(ExecutionMode.CONCURRENT) | ||
class DebouncedFunctionIntegrationTest { | ||
@Autowired | ||
private DevServerComponent devServer; | ||
|
||
@Autowired | ||
private Inngest client; | ||
|
||
@Test | ||
void testDebouncedFunctionExecutesTrailingEdge() throws Exception { | ||
String firstEvent = InngestFunctionTestHelpers.sendEvent(client, "test/debounced_2_second").getIds()[0]; | ||
String secondEvent = InngestFunctionTestHelpers.sendEvent(client, "test/debounced_2_second").getIds()[0]; | ||
|
||
Thread.sleep(4000); | ||
|
||
// With debouncing, the first event is skipped in favor of the second one because they were both sent within | ||
// the debounce period of 2 seconds | ||
assertEquals(0, devServer.runsByEvent(firstEvent).data.length); | ||
RunEntry<Object> secondRun = devServer.runsByEvent(secondEvent).first(); | ||
|
||
assertEquals("Completed", secondRun.getStatus()); | ||
assertEquals(42, secondRun.getOutput()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters