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

Cleanup and add workflow file #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Rust CI

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: zeroconf-tokio
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.os == 'windows-latest' && 'x86_64-pc-windows-msvc' || matrix.os == 'macos-latest' && 'x86_64-apple-darwin' || 'x86_64-unknown-linux-gnu' }}

- name: Prepare for Linux
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt -y install avahi-daemon libavahi-client-dev
sudo systemctl start avahi-daemon.service

- name: Prepare for Windows
if: matrix.os == 'windows-latest'
run: "choco install -y bonjour"

- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build

- name: Run tests
run: |
cargo test -- \
--skip browser::tests::it_discovers \
--skip browser::tests::it_discovers_multi_thread \
--skip browser::tests::it_drops_without_shutdown_gracefully \
--skip browser::tests::it_discovers_n_services \
--skip browser::tests::it_cannot_start_if_already_running

- name: Check formatting
run: cargo fmt -- --check

- name: Run Clippy
run: cargo clippy -- -D warnings
1 change: 1 addition & 0 deletions zeroconf-tokio/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl MdnsBrowserAsync {
self.inner.set_service_discovered_callback(callback);

let event_loop = self.inner.browse_services()?;

self.event_processor
.start_with_timeout(event_loop, timeout)?;

Expand Down
17 changes: 4 additions & 13 deletions zeroconf-tokio/src/event_processor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! Event processor for mDNS event loop.

use std::{
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;

use tokio::task::JoinHandle;
use zeroconf::{prelude::*, EventLoop};
Expand All @@ -21,10 +17,7 @@ pub struct EventProcessor {
impl EventProcessor {
/// Create a new event processor.
pub fn new() -> Self {
Self {
running: Arc::default(),
join_handle: None,
}
Self::default()
}

/// Check if the event processor is running.
Expand Down Expand Up @@ -81,8 +74,6 @@ impl EventProcessor {
.expect("should be able to join on the task");
}

self.join_handle = None;

debug!("mDNS event processor shut down");

Ok(())
Expand Down
1 change: 1 addition & 0 deletions zeroconf-tokio/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl MdnsServiceAsync {
self.inner.set_registered_callback(callback);

let event_loop = self.inner.register()?;

self.event_processor
.start_with_timeout(event_loop, timeout)?;

Expand Down
Loading