Skip to content

Commit 3d977ca

Browse files
committed
Try to implement sabr handling.
1 parent 49982d8 commit 3d977ca

15 files changed

Lines changed: 2574 additions & 6 deletions

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
branches:
8+
- main
9+
pull_request:
10+
paths-ignore:
11+
- "**.md"
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: Swatinem/rust-cache@v2
19+
- uses: rui314/setup-mold@v1
20+
- name: Set up NASM
21+
uses: ilammy/setup-nasm@v1.5.2
22+
- name: Run tests
23+
run: cargo test

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tokio = { version = "1.37.0", features = ["full"] }
1111
actix-web = "4.5.1"
1212
reqwest = { version = "0.12.9", features = ["stream", "brotli", "gzip", "socks"], default-features = false }
1313
qstring = "0.7.2"
14+
serde_json = "1.0"
1415

1516
# Alternate Allocator
1617
mimalloc = { version = "0.1.41", optional = true }
@@ -28,6 +29,8 @@ bytes = "1.9.0"
2829
futures-util = "0.3.30"
2930
listenfd = "1.0.1"
3031
http = "1.2.0"
32+
prost = "0.13.5"
33+
base64 = "0.22.1"
3134

3235
[features]
3336
default = ["webp", "mimalloc", "reqwest-rustls", "qhash"]

run_sabr_test.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# Colors for output
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
BLUE='\033[0;34m'
8+
NC='\033[0m' # No Color
9+
10+
echo -e "${BLUE}🚀 Starting SABR Test Environment${NC}"
11+
12+
# Function to cleanup background processes
13+
cleanup() {
14+
echo -e "\n${YELLOW}🧹 Cleaning up...${NC}"
15+
if [ ! -z "$SERVER_PID" ]; then
16+
kill $SERVER_PID 2>/dev/null
17+
echo -e "${YELLOW}Stopped server (PID: $SERVER_PID)${NC}"
18+
fi
19+
20+
# Show server logs if they exist
21+
if [ -f "server.log" ]; then
22+
echo -e "${BLUE}📋 Server logs:${NC}"
23+
tail -20 server.log
24+
fi
25+
26+
exit 0
27+
}
28+
29+
# Set trap to cleanup on script exit
30+
trap cleanup EXIT INT TERM
31+
32+
# Build and start the Rust server in the background
33+
echo -e "${BLUE}🔨 Building Rust server (debug)...${NC}"
34+
cargo build
35+
if [ $? -ne 0 ]; then
36+
echo -e "${RED}❌ Failed to build server${NC}"
37+
exit 1
38+
fi
39+
40+
echo -e "${BLUE}🌐 Starting server on port 8080...${NC}"
41+
RUST_LOG=debug ./target/debug/piped-proxy >server.log 2>&1 &
42+
SERVER_PID=$!
43+
44+
# Wait a moment for server to start
45+
sleep 3
46+
47+
# Check if server is running
48+
if ! kill -0 $SERVER_PID 2>/dev/null; then
49+
echo -e "${RED}❌ Server failed to start${NC}"
50+
if [ -f "server.log" ]; then
51+
echo -e "${RED}Server logs:${NC}"
52+
cat server.log
53+
fi
54+
exit 1
55+
fi
56+
57+
echo -e "${GREEN}✅ Server started (PID: $SERVER_PID)${NC}"
58+
59+
# Test server connectivity
60+
echo -e "${BLUE}🔍 Testing server connectivity...${NC}"
61+
if curl -s http://127.0.0.1:8080 >/dev/null; then
62+
echo -e "${GREEN}✅ Server is responding${NC}"
63+
else
64+
echo -e "${RED}❌ Server is not responding${NC}"
65+
exit 1
66+
fi
67+
68+
# Change to sabr_test directory and run the test
69+
echo -e "${BLUE}🧪 Running SABR test...${NC}"
70+
cd sabr_test
71+
72+
# Install dependencies if needed
73+
if [ ! -d "node_modules" ]; then
74+
echo -e "${BLUE}📦 Installing dependencies...${NC}"
75+
bun install
76+
fi
77+
78+
# Run the test with provided arguments or defaults
79+
echo -e "${GREEN}🎯 Starting SABR test...${NC}"
80+
timeout 30 bun run index.ts --verbose --duration 5 "$@"
81+
TEST_EXIT_CODE=$?
82+
83+
if [ $TEST_EXIT_CODE -eq 0 ]; then
84+
echo -e "${GREEN}✅ SABR test completed successfully!${NC}"
85+
elif [ $TEST_EXIT_CODE -eq 124 ]; then
86+
echo -e "${YELLOW}⏰ Test timed out (this might be expected)${NC}"
87+
else
88+
echo -e "${RED}❌ SABR test failed with exit code: $TEST_EXIT_CODE${NC}"
89+
fi
90+
91+
echo -e "${GREEN}🏁 Test completed${NC}"

sabr_test/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

sabr_test/bun.lock

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)