-
Notifications
You must be signed in to change notification settings - Fork 52
test: Test for breaking changes #1749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
chrfwow
wants to merge
11
commits into
open-feature:main
Choose a base branch
from
chrfwow:test-for-breaking-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5cd8410
add flagd dep
chrfwow 3c06a11
things
chrfwow a7e9f54
make test work
chrfwow a1dc8c2
add github actions
chrfwow bdc507b
add github actions
chrfwow 555f3c8
add github actions
chrfwow 362df55
add github actions
chrfwow e857b47
add github actions
chrfwow 6c7dbbe
refactor test
chrfwow b9d070d
revert github action
chrfwow 1db8a90
refactor test
chrfwow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
88 changes: 88 additions & 0 deletions
88
src/test/java/dev/openfeature/sdk/NoBreakingChangesTest.java
This file contains hidden or 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,88 @@ | ||
| package dev.openfeature.sdk; | ||
|
|
||
| import dev.openfeature.contrib.providers.flagd.Config; | ||
| import dev.openfeature.contrib.providers.flagd.FlagdOptions; | ||
| import dev.openfeature.contrib.providers.flagd.FlagdProvider; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.concurrent.ConcurrentLinkedQueue; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class NoBreakingChangesTest { | ||
|
|
||
| private AtomicBoolean isTestRunning; | ||
| private ConcurrentLinkedQueue<Throwable> uncaughtExceptions; | ||
| private Thread threadWatcher; | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| final var isRunning = new AtomicBoolean(true); | ||
| final var uncaught = new ConcurrentLinkedQueue<Throwable>(); | ||
| uncaughtExceptions = uncaught; | ||
| isTestRunning = isRunning; | ||
|
|
||
| threadWatcher = new Thread(() -> { | ||
| var seenThreads = new HashSet<Thread>(); | ||
| while (isRunning.get()) { | ||
| var stacks = Thread.getAllStackTraces(); | ||
| for (var entry : stacks.entrySet()) { | ||
| var thread = entry.getKey(); | ||
| if (seenThreads.add(thread)) { | ||
| thread.setUncaughtExceptionHandler((thread1, throwable) -> { | ||
| uncaught.add(throwable); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| threadWatcher.setDaemon(true); | ||
| threadWatcher.start(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void teardown() throws InterruptedException { | ||
| try { | ||
| Thread.sleep(1000); // wait a bit for any uncaught exceptions to be reported | ||
|
Check warning on line 50 in src/test/java/dev/openfeature/sdk/NoBreakingChangesTest.java
|
||
|
|
||
| isTestRunning.set(false); | ||
| threadWatcher.join(1000); | ||
| } finally { | ||
| assertThat(uncaughtExceptions).isEmpty(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void noBreakingChanges() { | ||
| var testProvider = new FlagdProvider(FlagdOptions.builder() | ||
| .resolverType(Config.Resolver.FILE) | ||
| .offlineFlagSourcePath(NoBreakingChangesTest.class | ||
| .getResource("/testFlags.json") | ||
| .getPath() | ||
| .replaceFirst("/", "")) | ||
| .build()); | ||
| var api = new OpenFeatureAPI(); | ||
| api.setProviderAndWait(testProvider); | ||
|
|
||
| var client = api.getClient(); | ||
| var flagFound = client.getBooleanDetails("basic-boolean", false); | ||
| assertThat(flagFound).isNotNull(); | ||
| assertThat(flagFound.getValue()).isTrue(); | ||
| assertThat(flagFound.getVariant()).isEqualTo("true"); | ||
| assertThat(flagFound.getReason()).isEqualTo(Reason.STATIC.toString()); | ||
|
|
||
| var flagNotFound = client.getStringDetails("unknown", "asd"); | ||
| assertThat(flagNotFound).isNotNull(); | ||
| assertThat(flagNotFound.getValue()).isEqualTo("asd"); | ||
| assertThat(flagNotFound.getVariant()).isNull(); | ||
| assertThat(flagNotFound.getReason()).isEqualTo(Reason.ERROR.toString()); | ||
| assertThat(flagNotFound.getErrorCode()).isEqualTo(ErrorCode.FLAG_NOT_FOUND); | ||
|
|
||
| testProvider.shutdown(); | ||
| api.shutdown(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| { | ||
| "$schema": "https://flagd.dev/schema/v0/flags.json", | ||
| "flags": { | ||
| "basic-boolean": { | ||
| "state": "ENABLED", | ||
| "defaultVariant": "true", | ||
| "variants": { | ||
| "true": true, | ||
| "false": false | ||
| }, | ||
| "targeting": {} | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert. This is my breaking change which I want to catch with this test