Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 0 additions & 9 deletions .github/actions/build-docs/action.yml

This file was deleted.

22 changes: 16 additions & 6 deletions .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: CI Workflow
description: 'Shared CI workflow.'
description: "Shared CI workflow."

inputs:
cargo-flags:
description: "Flags to pass to cargo commands."
required: false
default: ""

runs:
using: composite
Expand All @@ -10,20 +16,24 @@ runs:

- name: Run tests
shell: bash
run: cargo test --all-features -p eventsource-client
run: cargo test ${{ inputs.cargo-flags }} -p eventsource-client

- name: Run slower integration tests
shell: bash
run: cargo test ${{ inputs.cargo-flags }} -p eventsource-client --lib -- --ignored

- name: Run clippy checks
shell: bash
run: cargo clippy --all-features -p eventsource-client -- -D warnings
run: cargo clippy ${{ inputs.cargo-flags }} -p eventsource-client -- -D warnings

- name: Build contract tests
shell: bash
run: make build-contract-tests
run: CARGO_FLAGS="${{ inputs.cargo-flags }}" make build-contract-tests

- name: Start contract test service
shell: bash
run: make start-contract-test-service-bg
run: CARGO_FLAGS="${{ inputs.cargo-flags }}" make start-contract-test-service-bg

- name: Run contract tests
shell: bash
run: make run-contract-tests
run: CARGO_FLAGS="${{ inputs.cargo-flags }}" make run-contract-tests
47 changes: 44 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
name: Run CI
on:
push:
branches: [main]
branches:
- "main"
- "feat/**"
paths-ignore:
- "**.md" # Do not need to run CI for markdown changes.
pull_request:
branches: [main]
branches:
- "main"
- "feat/**"
paths-ignore:
- "**.md"

jobs:
ci-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features:
- name: "default"
cargo-flags: ""
- name: "hyper-rustls-native-roots"
cargo-flags: "--no-default-features --features hyper-rustls-native-roots"
- name: "hyper-rustls-webpki-roots"
cargo-flags: "--no-default-features --features hyper-rustls-webpki-roots"
- name: "native-tls"
cargo-flags: "--no-default-features --features native-tls"

name: CI (${{ matrix.features.name }})

steps:
- uses: actions/checkout@v4

- name: Get Rust version
id: rust-version
run: cat ./.github/variables/rust-versions.env >> $GITHUB_OUTPUT

- name: Get Rust version
id: rust-version
run: cat ./.github/variables/rust-versions.env >> $GITHUB_OUTPUT
Expand All @@ -26,4 +48,23 @@ jobs:
rustup component add rustfmt clippy

- uses: ./.github/actions/ci
- uses: ./.github/actions/build-docs
with:
cargo-flags: ${{ matrix.features.cargo-flags }}

build-docs:
runs-on: ubuntu-latest
name: Build Documentation (all features)

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup rust tooling
run: rustup override set nightly

- name: Install cargo-docs-rs
run: cargo install cargo-docs-rs

- name: Build documentation
run: cargo docs-rs -p eventsource-client
1 change: 0 additions & 1 deletion .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
rustup component add rustfmt clippy

- uses: ./.github/actions/ci
- uses: ./.github/actions/build-docs

- uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.2.0
name: "Get crates.io token"
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Run Release Please
on:
push:
branches:
- main
- "main"
- "feat/**"

jobs:
release-package:
Expand All @@ -26,6 +27,11 @@ jobs:
id: rust-version
run: cat ./.github/variables/rust-versions.env >> $GITHUB_OUTPUT

- name: Get Rust version
if: ${{ steps.release.outputs['eventsource-client--release_created'] == 'true' }}
id: rust-version
run: cat ./.github/variables/rust-versions.env >> $GITHUB_OUTPUT

- name: Setup rust tooling
if: ${{ steps.release.outputs['eventsource-client--release_created'] == 'true' }}
run: |
Expand All @@ -42,9 +48,6 @@ jobs:
- uses: ./.github/actions/ci
if: ${{ steps.release.outputs['eventsource-client--release_created'] == 'true' }}

- uses: ./.github/actions/build-docs
if: ${{ steps.release.outputs['eventsource-client--release_created'] == 'true' }}

- uses: ./.github/actions/publish
if: ${{ steps.release.outputs['eventsource-client--release_created'] == 'true' }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"eventsource-client": "0.16.2"
"eventsource-client": "0.16.2"
}
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
TEMP_TEST_OUTPUT=/tmp/contract-test-service.log
CARGO_FLAGS ?= ""

build-contract-tests:
@cargo build
@cargo build $(CARGO_FLAGS)

start-contract-test-service: build-contract-tests
@./target/debug/sse-test-api

start-contract-test-service-bg:
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"
@make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &
@$(MAKE) start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &

run-contract-tests:
@curl -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/v2.0.0/downloader/run.sh \
@curl -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/main/downloader/run.sh \
| VERSION=v2 PARAMS="-url http://localhost:8080 -debug -stop-service-at-end $(SKIPFLAGS) $(TEST_HARNESS_PARAMS)" sh

contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests
Expand Down
15 changes: 13 additions & 2 deletions contract-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ eventsource-client = { path = "../eventsource-client" }
serde_json = { version = "1.0.39"}
actix = { version = "0.13.1"}
actix-web = { version = "4"}
reqwest = { version = "0.11.6", default-features = false, features = ["json", "rustls-tls"] }
# reqwest is required for callback client (test harness communication)
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
env_logger = { version = "0.10.0" }
hyper = { version = "0.14.19", features = ["client", "http1", "tcp"] }
log = "0.4.6"
http = "1.0"
bytes = "1.5"

launchdarkly-sdk-transport = { version = "0.1.0" }

[[bin]]
name = "sse-test-api"

[features]
default = ["hyper"]
hyper = ["eventsource-client/hyper", "launchdarkly-sdk-transport/hyper"]
native-tls = ["hyper", "eventsource-client/native-tls"]
hyper-rustls-native-roots = ["hyper", "eventsource-client/hyper-rustls-native-roots"]
hyper-rustls-webpki-roots = ["hyper", "eventsource-client/hyper-rustls-webpki-roots"]
33 changes: 28 additions & 5 deletions contract-tests/src/bin/sse-test-api/stream_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use eventsource_client as es;
use launchdarkly_sdk_transport::HyperTransport;

use crate::{Config, EventType};

Expand Down Expand Up @@ -102,10 +103,6 @@ impl Inner {
reconnect_options = reconnect_options.delay(Duration::from_millis(delay_ms));
}

if let Some(read_timeout_ms) = config.read_timeout_ms {
client_builder = client_builder.read_timeout(Duration::from_millis(read_timeout_ms));
}

if let Some(last_event_id) = &config.last_event_id {
client_builder = client_builder.last_event_id(last_event_id.clone());
}
Expand All @@ -127,8 +124,34 @@ impl Inner {
}
}

// Build with HyperTransport
let mut transport_builder = HyperTransport::builder();

if let Some(timeout_ms) = config.read_timeout_ms {
transport_builder = transport_builder.read_timeout(Duration::from_millis(timeout_ms));
}

#[cfg(any(
feature = "hyper-rustls-native-roots",
feature = "hyper-rustls-webpki-roots",
feature = "native-tls"
))]
let transport = transport_builder
.build_https()
.map_err(|e| format!("Failed to build HTTPS transport: {e:?}"))?;
#[cfg(not(any(
feature = "hyper-rustls-native-roots",
feature = "hyper-rustls-webpki-roots",
feature = "native-tls"
)))]
let transport = transport_builder
.build_http()
.map_err(|e| format!("Failed to build HTTP transport: {e:?}"))?;

Ok(Box::new(
client_builder.reconnect(reconnect_options.build()).build(),
client_builder
.reconnect(reconnect_options.build())
.build_with_transport(transport),
))
}
}
Expand Down
21 changes: 12 additions & 9 deletions eventsource-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ keywords = ["launchdarkly", "feature-flags", "feature-toggles", "eventsource", "
exclude = ["CHANGELOG.md"]

[dependencies]
bytes = "1.5"
futures = "0.3.21"
hyper = { version = "0.14.19", features = ["client", "http1", "tcp"] }
hyper-rustls = { version = "0.24.1", optional = true }
http = "1.0"
log = "0.4.6"
pin-project = "1.0.10"
tokio = { version = "1.17.0", features = ["time"] }
hyper-timeout = "0.4.1"
rand = "0.8.5"
base64 = "0.22.1"

launchdarkly-sdk-transport = { version = "0.1.0" }

[dev-dependencies]
env_logger = "0.10.0"
maplit = "1.0.1"
Expand All @@ -30,11 +31,13 @@ tokio = { version = "1.2.0", features = ["macros", "rt-multi-thread"] }
test-case = "3.2.1"
proptest = "1.0.0"


[features]
default = ["rustls"]
rustls = ["hyper-rustls", "hyper-rustls/http2"]

[[example]]
name = "tail"
required-features = ["rustls"]
required-features = ["hyper"]

[features]
default = ["hyper"]
hyper = ["launchdarkly-sdk-transport/hyper"]
native-tls = ["hyper", "launchdarkly-sdk-transport/native-tls"]
hyper-rustls-native-roots = ["hyper", "launchdarkly-sdk-transport/hyper-rustls-native-roots"]
hyper-rustls-webpki-roots = ["hyper", "launchdarkly-sdk-transport/hyper-rustls-webpki-roots"]
Loading