-
Notifications
You must be signed in to change notification settings - Fork 5
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
Migrate waitForConnectionToBeUsable() to react to pushed connection event state changes #882
Merged
+519
−201
Merged
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4da348a
Working, but there are tiny gaps when there are no observers. Need to…
jlrobins 017c285
Transition waitForConnectionToBeUsable() to be based on received even…
jlrobins 3d541b2
Reveryt changes
jlrobins bc84f64
Merge remote-tracking branch 'origin/main' into wensocket_connection_…
jlrobins 4a4325e
Purge prior cached connection state before updating a connection spec…
jlrobins ea91055
Fix tests
jlrobins 17e91c0
Fix remainder tests.
jlrobins 819dd84
Trim unneeded fat
jlrobins e458832
Tests over connectionStatusUtils::isConnectionStable.
jlrobins 468dc2a
Revert stray comment.
jlrobins 03ab948
Revert stray comment.
jlrobins f6cf88b
Better comments, organization.
jlrobins 4edf39a
filter -> predicate
jlrobins 7fec984
Changeloggery.
jlrobins 8d20006
Merge remote-tracking branch 'origin/main' into wensocket_connection_…
jlrobins ce56a60
Respell away from old name in comments / test descriptions.
jlrobins 4474164
Merge remote-tracking branch 'origin/main' into wensocket_connection_…
jlrobins 36939ca
Address PR comments.
jlrobins 843fff8
Address PR comments.
jlrobins 464ed0e
Get the connection loading spinny back.
jlrobins 3398546
Fix pasto
jlrobins 5064a25
Remove blank line
jlrobins 78b61fe
Fix name
jlrobins 647c6f5
Fix corner cases of direct connection loading states.
jlrobins 5e191d7
Fix direct connection loading state.
jlrobins aa60036
Cache
jlrobins 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
v0.134.1 | ||
v0.139.0 | ||
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
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
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,73 @@ | ||
// tests over isConnectionStable | ||
|
||
import * as assert from "assert"; | ||
|
||
import { | ||
TEST_CCLOUD_CONNECTION, | ||
TEST_DIRECT_CONNECTION, | ||
TEST_LOCAL_CONNECTION, | ||
} from "../../tests/unit/testResources/connection"; | ||
|
||
import { ConnectedState, Status } from "../clients/sidecar/models"; | ||
import { isConnectionStable } from "./connectionStatusUtils"; | ||
|
||
describe("isConnectionStable", () => { | ||
const testAuthStatus = { authentication: { status: Status.NoToken } }; | ||
|
||
it("ccloud connection tests", () => { | ||
type CCloudConnectionStateAndResult = [ConnectedState, boolean]; | ||
|
||
// ccloud connection is stable if not in Attempting state | ||
const testCases: CCloudConnectionStateAndResult[] = [ | ||
[ConnectedState.None, false], | ||
[ConnectedState.Attempting, true], | ||
[ConnectedState.Success, true], | ||
[ConnectedState.Expired, true], | ||
[ConnectedState.Failed, true], | ||
]; | ||
|
||
for (const [connectedState, expectedResult] of testCases) { | ||
const testConnection = { | ||
...TEST_CCLOUD_CONNECTION, | ||
status: { | ||
ccloud: { state: connectedState }, | ||
...testAuthStatus, | ||
}, | ||
}; | ||
assert.strictEqual(isConnectionStable(testConnection), expectedResult); | ||
} | ||
}); | ||
|
||
it("direct connection tests", () => { | ||
type LocalConnectionStatesAndResult = [ConnectedState, ConnectedState, boolean]; | ||
|
||
// direct connection is stable if neither kafka nor schema registry are attempting | ||
const testCases: LocalConnectionStatesAndResult[] = [ | ||
[ConnectedState.None, ConnectedState.None, true], | ||
[ConnectedState.None, ConnectedState.Success, true], | ||
[ConnectedState.Success, ConnectedState.None, true], | ||
[ConnectedState.Attempting, ConnectedState.None, false], | ||
[ConnectedState.None, ConnectedState.Attempting, false], | ||
[ConnectedState.Attempting, ConnectedState.Attempting, false], | ||
[ConnectedState.Success, ConnectedState.Success, true], | ||
[ConnectedState.Expired, ConnectedState.Expired, true], | ||
[ConnectedState.Failed, ConnectedState.Failed, true], | ||
]; | ||
|
||
for (const [kafkaState, schemaRegistryState, expectedResult] of testCases) { | ||
const testConnection = { | ||
...TEST_DIRECT_CONNECTION, | ||
status: { | ||
kafka_cluster: { state: kafkaState }, | ||
schema_registry: { state: schemaRegistryState }, | ||
...testAuthStatus, | ||
}, | ||
}; | ||
assert.strictEqual(isConnectionStable(testConnection), expectedResult); | ||
} | ||
}); | ||
|
||
it("should raise when asked about a local connection (not implemented yet)", () => { | ||
assert.throws(() => isConnectionStable(TEST_LOCAL_CONNECTION)); | ||
}); | ||
}); |
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,50 @@ | ||
// helpers for connection status testing, factored out for test spying | ||
jlrobins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { Connection, ConnectionType } from "../clients/sidecar/models"; | ||
import { Logger } from "../logging"; | ||
|
||
const logger = new Logger("connectionStatusUtils"); | ||
|
||
export function isConnectionStable(connection: Connection): boolean { | ||
const type = connection.spec.type!; | ||
|
||
switch (type) { | ||
case ConnectionType.Ccloud: | ||
return isCCloudConnectionStable(connection); | ||
case ConnectionType.Direct: | ||
return isDirectConnectionStable(connection); | ||
default: | ||
logger.warn(`isConnectionStable: unhandled connection type ${type}`); | ||
throw new Error(`Unhandled connection type ${type}`); | ||
} | ||
} | ||
|
||
function isCCloudConnectionStable(connection: Connection): boolean { | ||
const status = connection.status; | ||
const ccloudState = status.ccloud!.state; | ||
|
||
const rv = ccloudState !== "NONE"; | ||
|
||
const ccloudFailed = status.ccloud?.errors?.sign_in?.message; | ||
shouples marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (ccloudFailed) { | ||
logger.error(`isCCloudConnectionStable(): auth failed with error: ${ccloudFailed}`); | ||
} | ||
|
||
logger.debug(`isCCloudConnectionStable(): returning ${rv} based on state ${ccloudState}`); | ||
|
||
return rv; | ||
} | ||
|
||
function isDirectConnectionStable(connection: Connection): boolean { | ||
const status = connection.status; | ||
const kafkaState = status.kafka_cluster?.state; | ||
const schemaRegistryState = status.schema_registry?.state; | ||
|
||
const rv = kafkaState !== "ATTEMPTING" && schemaRegistryState !== "ATTEMPTING"; | ||
|
||
logger.debug( | ||
`isDirectConnectionStable(): returning ${rv} for connection ${connection.id} based on kafkaState ${kafkaState} and schemaRegistryState ${schemaRegistryState}`, | ||
); | ||
shouples marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return rv; | ||
} |
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.
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.
Need fix for ccloud connection java.time.Instant serialization-over-websocket.