Skip to content

Commit ce1f4a0

Browse files
author
Harsh Dev Pathak
committed
feat: Added CI for in_memory_testing
1 parent 1b5c064 commit ce1f4a0

File tree

4 files changed

+209
-24
lines changed

4 files changed

+209
-24
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: In-Memory VSS Server CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
test-in-memory:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Create in-memory config
22+
run: |
23+
mkdir -p rust/server
24+
cat > rust/server/vss-server-config.toml <<EOF
25+
[server_config]
26+
host = "127.0.0.1"
27+
port = 8080
28+
store_type = "in_memory"
29+
EOF
30+
31+
- name: Build server
32+
working-directory: rust
33+
run: cargo build --release --bin vss-server
34+
35+
- name: Start VSS server
36+
working-directory: rust
37+
run: |
38+
./target/release/vss-server ./server/vss-server-config.toml > server.log 2>&1 &
39+
echo "Server PID: $!"
40+
41+
- name: Wait for server
42+
run: |
43+
for i in {1..15}; do
44+
if curl -s http://127.0.0.1:8080 > /dev/null; then
45+
echo "Server is up!"
46+
exit 0
47+
fi
48+
sleep 1
49+
done
50+
echo "Server failed. Dumping log:"
51+
cat rust/server.log
52+
exit 1
53+
54+
- name: HTTP Smoke Test
55+
run: |
56+
curl -f \
57+
-H "Authorization: Bearer test_user" \
58+
--data-binary @<(echo "0A04746573741A150A026B3110FFFFFFFFFFFFFFFFFF011A046B317631" | xxd -r -p) \
59+
http://127.0.0.1:8080/vss/putObjects
60+
61+
RESPONSE=$(curl -f \
62+
-H "Authorization: Bearer test_user" \
63+
--data-binary @<(echo "0A047465737412026B31" | xxd -r -p) \
64+
http://127.0.0.1:8080/vss/getObject)
65+
66+
- name: Run unit tests
67+
working-directory: rust
68+
run: cargo test --package impls --lib -- in_memory_store::tests --nocapture

.github/workflows/ldk-node-integration.yml

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ concurrency:
77
cancel-in-progress: true
88

99
jobs:
10-
build-and-test:
10+
test-postgres:
1111
runs-on: ubuntu-latest
12-
12+
timeout-minutes: 20
1313
services:
1414
postgres:
1515
image: postgres:latest
16-
ports:
17-
- 5432:5432
16+
ports: [5432:5432]
1817
env:
1918
POSTGRES_DB: postgres
2019
POSTGRES_USER: postgres
@@ -30,20 +29,105 @@ jobs:
3029
uses: actions/checkout@v3
3130
with:
3231
path: vss-server
32+
3333
- name: Checkout LDK Node
3434
uses: actions/checkout@v3
3535
with:
3636
repository: lightningdevkit/ldk-node
3737
path: ldk-node
3838

39-
- name: Build and Deploy VSS Server
39+
- name: Create Postgres config
40+
run: |
41+
mkdir -p vss-server/rust/server
42+
cat > vss-server/rust/server/vss-server-config.toml <<EOF
43+
[server_config]
44+
host = "127.0.0.1"
45+
port = 8080
46+
store_type = "postgres"
47+
[postgresql_config]
48+
host = "localhost"
49+
port = 5432
50+
database = "postgres"
51+
username = "postgres"
52+
password = "postgres"
53+
EOF
54+
55+
- name: Build & Start VSS Server
56+
working-directory: vss-server/rust
4057
run: |
41-
cd vss-server/rust
42-
cargo build
43-
cargo run server/vss-server-config.toml&
58+
cargo build --release --bin vss-server
59+
./target/release/vss-server ./server/vss-server-config.toml > server.log 2>&1 &
60+
echo "Server PID: $!"
61+
62+
- name: Wait for VSS
63+
run: |
64+
for i in {1..30}; do
65+
if curl -s http://127.0.0.1:8080/vss > /dev/null; then
66+
echo "VSS ready"
67+
exit 0
68+
fi
69+
sleep 2
70+
done
71+
echo "VSS failed:"
72+
cat vss-server/rust/vss.log
73+
exit 1
74+
4475
- name: Run LDK Node Integration tests
76+
working-directory: ldk-node
4577
run: |
46-
cd ldk-node
47-
export TEST_VSS_BASE_URL="http://localhost:8080/vss"
78+
export TEST_VSS_BASE_URL="http://127.0.0.1:8080/vss"
4879
RUSTFLAGS="--cfg vss_test" cargo test io::vss_store
4980
RUSTFLAGS="--cfg vss_test" cargo test --test integration_tests_vss
81+
82+
test-in-memory:
83+
runs-on: ubuntu-latest
84+
timeout-minutes: 10
85+
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v3
89+
with:
90+
path: vss-server
91+
92+
- name: Checkout LDK Node
93+
uses: actions/checkout@v3
94+
with:
95+
repository: lightningdevkit/ldk-node
96+
path: ldk-node
97+
98+
- name: Create In-Memory config
99+
run: |
100+
mkdir -p vss-server/rust/server
101+
cat > vss-server/rust/server/vss-server-config.toml <<EOF
102+
[server_config]
103+
host = "127.0.0.1"
104+
port = 8080
105+
store_type = "in_memory"
106+
EOF
107+
108+
- name: Build & Start VSS Server
109+
working-directory: vss-server/rust
110+
run: |
111+
cargo build --release --bin vss-server
112+
./target/release/vss-server ./server/vss-server-config.toml > server.log 2>&1 &
113+
echo "Server PID: $!"
114+
115+
- name: Wait for VSS
116+
run: |
117+
for i in {1..30}; do
118+
if curl -s http://127.0.0.1:8080/vss > /dev/null; then
119+
echo "VSS ready"
120+
exit 0
121+
fi
122+
sleep 1
123+
done
124+
echo "VSS failed:"
125+
cat vss-server/rust/vss.log
126+
exit 1
127+
128+
- name: Run LDK Node Integration tests
129+
working-directory: ldk-node
130+
run: |
131+
export TEST_VSS_BASE_URL="http://127.0.0.1:8080/vss"
132+
RUSTFLAGS="--cfg vss_test" cargo test io::vss_store
133+
RUSTFLAGS="--cfg vss_test" cargo test --test integration_tests_vss

rust/impls/src/in_memory_store.rs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
use std::collections::HashMap;
2-
use std::sync::Arc;
3-
4-
use async_trait::async_trait;
5-
use bytes::Bytes;
6-
use chrono::prelude::Utc;
7-
use tokio::sync::Mutex;
8-
91
use crate::postgres_store::{
102
VssDbRecord, LIST_KEY_VERSIONS_MAX_PAGE_SIZE, MAX_PUT_REQUEST_ITEM_COUNT,
113
};
@@ -15,6 +7,12 @@ use api::types::{
157
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, KeyValue,
168
ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse,
179
};
10+
use async_trait::async_trait;
11+
use bytes::Bytes;
12+
use chrono::prelude::Utc;
13+
use std::collections::HashMap;
14+
use std::sync::Arc;
15+
use tokio::sync::Mutex;
1816

1917
fn build_vss_record(user_token: String, store_id: String, kv: KeyValue) -> VssDbRecord {
2018
let now = Utc::now();
@@ -227,6 +225,7 @@ impl KvStore for InMemoryBackendImpl {
227225
let guard = self.store.lock().await;
228226

229227
if let Some(record) = guard.get(&key) {
228+
eprintln!("GET key found for user request {},{},{:?}", key, user_token, request);
230229
Ok(GetObjectResponse {
231230
value: Some(KeyValue {
232231
key: record.key.clone(),
@@ -235,6 +234,10 @@ impl KvStore for InMemoryBackendImpl {
235234
}),
236235
})
237236
} else if request.key == GLOBAL_VERSION_KEY {
237+
eprintln!(
238+
"GET key== global version key{}, {}, {}, {:?}",
239+
key, GLOBAL_VERSION_KEY, user_token, request
240+
);
238241
Ok(GetObjectResponse {
239242
value: Some(KeyValue {
240243
key: GLOBAL_VERSION_KEY.to_string(),
@@ -247,6 +250,7 @@ impl KvStore for InMemoryBackendImpl {
247250
}),
248251
})
249252
} else {
253+
eprintln!("GET requested key not found {},{},{:?}", key, user_token, request);
250254
Err(VssError::NoSuchKeyError("Requested key not found.".to_string()))
251255
}
252256
}
@@ -256,13 +260,19 @@ impl KvStore for InMemoryBackendImpl {
256260
) -> Result<PutObjectResponse, VssError> {
257261
if request.transaction_items.len() + request.delete_items.len() > MAX_PUT_REQUEST_ITEM_COUNT
258262
{
263+
eprintln!(
264+
"PUT Number of write items per request should be less than equal to {}",
265+
MAX_PUT_REQUEST_ITEM_COUNT
266+
);
259267
return Err(VssError::InvalidRequestError(format!(
260268
"Number of write items per request should be less than equal to {}",
261269
MAX_PUT_REQUEST_ITEM_COUNT
262270
)));
263271
}
264272

265273
let store_id = request.store_id.clone();
274+
eprintln!("PUT storeid is {} and other data is {},{:?}", store_id, user_token, request);
275+
266276
let mut guard = self.store.lock().await;
267277

268278
let mut vss_put_records: Vec<VssDbRecord> = request
@@ -315,10 +325,11 @@ impl KvStore for InMemoryBackendImpl {
315325
let key_value = request.key_value.ok_or_else(|| {
316326
VssError::InvalidRequestError("key_value missing in DeleteObjectRequest".to_string())
317327
})?;
328+
318329
let store_id = request.store_id.clone();
319330
let mut guard = self.store.lock().await;
320-
321331
let vss_record = build_vss_record(user_token.clone(), store_id.clone(), key_value);
332+
322333
execute_delete_object(&mut guard, &user_token, &store_id, &vss_record);
323334

324335
Ok(DeleteObjectResponse {})
@@ -333,6 +344,11 @@ impl KvStore for InMemoryBackendImpl {
333344
let page_size = request.page_size.unwrap_or(i32::MAX);
334345
let limit = std::cmp::min(page_size, LIST_KEY_VERSIONS_MAX_PAGE_SIZE) as usize;
335346

347+
eprintln!(
348+
"LIST data is {}, {}, {}, {}, {}",
349+
store_id, key_prefix, page_token, page_size, limit
350+
);
351+
336352
let guard = self.store.lock().await;
337353

338354
let mut global_version = None;
@@ -341,7 +357,6 @@ impl KvStore for InMemoryBackendImpl {
341357
}
342358

343359
let storage_prefix = format!("{}#{}#", user_token, store_id);
344-
345360
let mut keys_with_versions: Vec<(String, i64)> = Vec::new();
346361

347362
for (storage_key, r) in guard.iter() {
@@ -380,10 +395,24 @@ impl KvStore for InMemoryBackendImpl {
380395
.map(|(key, version)| KeyValue { key, value: Bytes::new(), version })
381396
.collect();
382397

383-
let mut next_page_token = Some("".to_string());
384-
if !page_items.is_empty() {
385-
next_page_token = page_items.last().map(|kv| kv.key.clone());
386-
}
398+
let next_page_token = if page_items.is_empty() {
399+
eprintln!("LIST returning empty page with empty token");
400+
Some("".to_string())
401+
} else {
402+
eprintln!(
403+
"LIST returning {} items, last key: {:?}",
404+
page_items.len(),
405+
page_items.last().map(|kv| &kv.key)
406+
);
407+
page_items.last().map(|kv| kv.key.clone())
408+
};
409+
410+
eprintln!(
411+
"LIST final response - items: {}, next_token: {:?}, global_version: {:?}",
412+
page_items.len(),
413+
next_page_token,
414+
global_version
415+
);
387416

388417
Ok(ListKeyVersionsResponse { key_versions: page_items, next_page_token, global_version })
389418
}

rust/server/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ prost = { version = "0.11.6", default-features = false, features = ["std"] }
1515
bytes = "1.4.0"
1616
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
1717
toml = { version = "0.8.9", default-features = false, features = ["parse"] }
18+
19+
[[bin]]
20+
name = "vss-server"
21+
path = "src/main.rs"

0 commit comments

Comments
 (0)