Skip to content
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

release/0.3.1 #4

Merged
merged 26 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9fbca35
feat: support any gateway
ilbertt Nov 24, 2023
6742379
refactor: split in files
ilbertt Nov 24, 2023
3f28de2
perf: docs fixes
ilbertt Nov 24, 2023
e62af23
fix: don't check validity in with_...
ilbertt Nov 24, 2023
5ea8ecb
fix: integration tests
ilbertt Nov 27, 2023
de5b3e1
feat: canister has only one logic in get_messages
ilbertt Nov 27, 2023
111942b
fix: gateways must be removed when resetting state
ilbertt Nov 27, 2023
895c20c
feat: return is_end_of_queue for polling
ilbertt Nov 27, 2023
ff546f7
chore: disable tests on draft PRs
ilbertt Nov 27, 2023
e201207
perf: move get_current_time to utils
ilbertt Nov 27, 2023
1524824
wip: delete old messages from queue
ilbertt Nov 27, 2023
dedfa30
fix: gateway principals, decrement clients count
ilbertt Nov 29, 2023
6c073ad
fix: get_current_time unix timestamp in tests
ilbertt Nov 29, 2023
d93d2e9
chore: delete old messages unit tests
ilbertt Nov 29, 2023
9de3dbb
chore: refactor integration tests folder
ilbertt Nov 29, 2023
6ea388e
chore: disable backtrace in integration tests
ilbertt Nov 29, 2023
155d0f6
perf: typos
ilbertt Nov 29, 2023
972f1c5
fix: delete messages before setting certificate
ilbertt Nov 29, 2023
1ecd452
perf: unneeded matches
ilbertt Nov 29, 2023
52f5be4
fix: check if gateway is registered in ws_close
ilbertt Nov 29, 2023
5de977a
fix: delete old messages integration tests
ilbertt Nov 29, 2023
7ca9b77
fix: integration tests
ilbertt Nov 29, 2023
a7ef0c4
feat: increase default parameters
ilbertt Nov 29, 2023
ba8bef1
fix: update candid types
ilbertt Dec 1, 2023
fe627fb
refactor: timers small refactor, comments
ilbertt Dec 3, 2023
4ff0311
fix: remove client if it was connected on ws_open
ilbertt Dec 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ on:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
unit-and-integration-tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cargo test --package ic-websocket-cdk --doc

./scripts/build-test-canister.sh

POCKET_IC_BIN="$(pwd)/bin/pocket-ic" RUST_BACKTRACE=1 cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
POCKET_IC_BIN="$(pwd)/bin/pocket-ic" cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
2 changes: 1 addition & 1 deletion src/ic-websocket-cdk/service.example.did
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./ws_types.did";

// define your message type here
type MyMessageType = {
type MyMessageType = record {
some_field : text;
};

Expand Down
109 changes: 109 additions & 0 deletions src/ic-websocket-cdk/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use std::{error::Error, fmt};

use crate::{ClientKey, ClientPrincipal, GatewayPrincipal};

#[derive(Debug)]
pub(crate) enum WsError<'a> {
AnonymousPrincipalNotAllowed,
ClientKeyAlreadyConnected {
client_key: &'a ClientKey,
},
ClientKeyMessageMismatch {
client_key: &'a ClientKey,
},
ClientKeyNotConnected {
client_key: &'a ClientKey,
},
ClientNotRegisteredToGateway {
client_key: &'a ClientKey,
gateway_principal: &'a GatewayPrincipal,
},
ClientPrincipalNotConnected {
client_principal: &'a ClientPrincipal,
},
DecodeServiceMessageContent {
err: candid::Error,
},
ExpectedIncomingMessageToClientNumNotInitialized {
client_key: &'a ClientKey,
},
GatewayNotRegistered {
gateway_principal: &'a GatewayPrincipal,
},
InvalidServiceMessage,
IncomingSequenceNumberWrong {
expected_sequence_num: u64,
actual_sequence_num: u64,
},
OutgoingMessageToClientNumNotInitialized {
client_key: &'a ClientKey,
},
}

impl WsError<'_> {
pub(crate) fn to_string_result(&self) -> Result<(), String> {
Err(self.to_string())
}
}

impl fmt::Display for WsError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let msg = match self {
WsError::AnonymousPrincipalNotAllowed => {
"Anonymous principal is not allowed".to_string()
},
WsError::ClientKeyAlreadyConnected { client_key } => {
format!("Client with key {client_key} already has an open connection")
},
WsError::ClientKeyMessageMismatch { client_key } => {
format!(
"Client with principal {} has a different key than the one used in the message",
client_key.client_principal,
)
},
WsError::ClientKeyNotConnected { client_key } => {
format!("Client with key {client_key} doesn't have an open connection")
},
WsError::ClientNotRegisteredToGateway {
client_key,
gateway_principal,
} => {
format!(
"Client with key {client_key} was not registered to gateway {gateway_principal}"
)
},
WsError::ClientPrincipalNotConnected { client_principal } => {
format!("Client with principal {client_principal} doesn't have an open connection")
},
WsError::DecodeServiceMessageContent { err } => {
format!("Error decoding service message content: {err}")
},
WsError::ExpectedIncomingMessageToClientNumNotInitialized { client_key } => {
format!(
"Expected incoming message to client num not initialized for client key {client_key}"
)
},
WsError::GatewayNotRegistered { gateway_principal } => {
format!("Gateway with principal {gateway_principal} is not registered")
},
WsError::InvalidServiceMessage => "Invalid service message".to_string(),
WsError::IncomingSequenceNumberWrong {
expected_sequence_num,
actual_sequence_num,
} => {
format!(
"Expected incoming sequence number {expected_sequence_num} but got {actual_sequence_num}"
)
},
WsError::OutgoingMessageToClientNumNotInitialized { client_key } => {
format!(
"Outgoing message to client num not initialized for client key {client_key}"
)
},
};

write!(f, "{}", msg)
}
}

impl Error for WsError<'_> {}
Loading
Loading