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

upgraded with hearbeat #14

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5bd5651
updated code
Oct 14, 2024
17c2642
blocked multi join without leave
Oct 14, 2024
ace7493
Update main.rs
learnwithsobhit Oct 15, 2024
a7cad33
Merge branch 'main' into sc-working-branch
Oct 15, 2024
c09ba1a
updated
Oct 15, 2024
fa55899
Merge branch 'sc-working-branch'
Oct 15, 2024
a66fd0a
updated close handle
Oct 15, 2024
4472fa4
cleanup
Oct 15, 2024
9a9787e
formated
Oct 15, 2024
e48c384
Create server.sh
learnwithsobhit Oct 15, 2024
f814928
Create client.sh
learnwithsobhit Oct 15, 2024
2487d49
Update main.rs
learnwithsobhit Oct 15, 2024
2a2ff36
Update main.rs
learnwithsobhit Oct 15, 2024
a128fa1
Update main.rs
learnwithsobhit Oct 15, 2024
e1b21f9
updated readme
Oct 15, 2024
3bd9336
Merge branch 'sc-working-branch'
Oct 15, 2024
82f62e3
updated ci
Oct 16, 2024
95c2849
Merge branch 'main' into sc-working-branch
Oct 16, 2024
45cd82e
Update ci.yml
learnwithsobhit Oct 16, 2024
7451fcc
Update README.md
learnwithsobhit Oct 16, 2024
7e9e9e0
refactored
Oct 16, 2024
bd5ec94
updated
Oct 16, 2024
37410a3
Merge branch 'sc-working-branch'
Oct 16, 2024
1aa6b27
updated
Oct 16, 2024
bf16b7d
Merge branch 'main' into sc-working-branch
Oct 16, 2024
a62c4fc
video
Oct 16, 2024
8b10570
removed unwrap
Oct 17, 2024
6db5cc3
updated
Oct 17, 2024
96f00ef
updated
Oct 17, 2024
7e7ec09
updated
Oct 17, 2024
78a9655
updated
Oct 17, 2024
5f19a8b
updated
Oct 17, 2024
6559dc2
Update utils.rs
learnwithsobhit Oct 17, 2024
cc69927
Update main.rs
learnwithsobhit Oct 17, 2024
4db38f0
Update main.rs
learnwithsobhit Oct 17, 2024
50af102
updated
Oct 18, 2024
d1cb9a9
updated
Oct 18, 2024
7ab85bc
updated
Oct 19, 2024
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
44 changes: 44 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

echo "Running pre-commit checks..."
# Format all Rust files
echo "\nChecking formatting..."
cargo fmt -- --check
if [ $? -ne 0 ]; then
echo "Formatting check failed. Please run 'cargo fmt' and commit again."
exit 1
fi

# Check compilation
echo "\nChecking compilation..."
cargo check
if [ $? -ne 0 ]; then
echo "Compilation check failed. Please fix the errors and commit again."
exit 1
fi

echo "\nChecking release compilation..."
cargo check --release
if [ $? -ne 0 ]; then
echo "Release compilation check failed. Please fix the errors and commit again."
exit 1
fi

# Run clippy
echo "\nRunning clippy..."
cargo clippy -- -D warnings
if [ $? -ne 0 ]; then
echo "Clippy check failed. Please fix the warnings and commit again."
exit 1
fi

# Run all tests
echo "\nRunning tests..."
cargo test
if [ $? -ne 0 ]; then
echo "Tests failed. Please fix the failing tests and commit again."
exit 1
fi

echo "\nAll checks completed successfully."
exit 0
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Chat Server Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Build server and client
run: |
cargo build --bin server
cargo build --bin client

- name: Set log level
run: export RUST_LOG=info

- name: Run server
run: cargo run --bin server 0.0.0.00:12345 &

- name: Wait for server to start
run: sleep 5

- name: Run client and send test message
run: |
cargo run --bin client 127.0.0.1:12345 TestUser > client_log.txt 2>&1 &
sleep 5 # Give some time for the message to be sent and processed

- name: Check client logs
run: |
if grep -q "Welcome to the chat, TestUser!" client_log.txt; then
echo "client connected to server"
else
echo "client did not connect to server"
cat client_log.txt
exit 1
fi

- name: Check for failures
run: |
if [ $? -ne 0 ]; then
echo "Client or server exited with a failure"
exit 1
else
echo "Client and server ran successfully"
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

*.vscode
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = [
"server",
"client",
"common",
]

resolver = "2"
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,27 @@ without error, and is free of clippy errors.
send a message to the server from the client. Make sure that niether the server
or client exit with a failure. This action should be run anytime new code
is pushed to a branch or landed on the main branch.

## Run pre-commit hook:
```
sh .githooks/pre-commit
```

## Run tests:
```
cargo test
```

## Launch server:
```
cargo run --bin server <ip>:<port>
```

## Launch client:
```
cargo run --bin client <ip>:<port> <username>
```

## GitHub Actions

The GitHub Actions workflow is defined in `.github/workflows/ci.yml`. It will run the server and client and check if the client can send a message to the server.
2 changes: 2 additions & 0 deletions client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
RUST_LOG=info cargo run --bin client $1:$2 $3
15 changes: 15 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "client"
version = "0.1.0"
edition = "2021"

[dependencies]
env_logger = "0.11.5"
futures-util = "0.3.31"
log = "0.4.22"
tokio = { version = "1.40.0", features = ["full"] }
tokio-tungstenite = "0.24.0"
common = { path = "../common" }
[dev-dependencies]
tokio-test = "0.4.4"
futures = "0.3.31"
Loading