Skip to content

Commit 502b0b4

Browse files
committed
Compact the code coverage tasks
There is no need to run twice the tests the same way.
1 parent 7acce86 commit 502b0b4

File tree

2 files changed

+27
-65
lines changed

2 files changed

+27
-65
lines changed

.github/workflows/libp2p-rust-dht.yml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -233,47 +233,6 @@ jobs:
233233
exit 1
234234
fi
235235
236-
weighted-code-coverage:
237-
238-
needs: [build, docs]
239-
240-
runs-on: ubuntu-latest
241-
242-
services:
243-
postgres:
244-
image: postgres
245-
env:
246-
POSTGRES_PASSWORD: mysecretpassword
247-
options: >-
248-
--health-cmd pg_isready
249-
--health-interval 10s
250-
--health-timeout 5s
251-
--health-retries 5
252-
ports:
253-
- 5432:5432
254-
255-
steps:
256-
- uses: actions/checkout@v3
257-
258-
- name: Install protobuf compiler
259-
run: |
260-
sudo apt-get update
261-
sudo apt-get install protobuf-compiler
262-
263-
- name: Install Rust stable
264-
uses: dtolnay/rust-toolchain@stable
265-
with:
266-
toolchain: stable
267-
268-
- name: Install grcov
269-
env:
270-
GRCOV_LINK: https://github.com/mozilla/grcov/releases/download
271-
GRCOV_VERSION: v0.8.13
272-
GRCOV_BINARY: grcov-x86_64-unknown-linux-musl.tar.bz2
273-
run: |
274-
curl -L "$GRCOV_LINK/$GRCOV_VERSION/$GRCOV_BINARY" |
275-
tar xj -C $HOME/.cargo/bin
276-
277236
- name: Install weighted-code-coverage
278237
env:
279238
WCC_LINK: https://github.com/SoftengPoliTo/weighted-code-coverage/releases/download
@@ -283,23 +242,7 @@ jobs:
283242
curl -L "$WCC_LINK/$WCC_VERSION/$WCC_BINARY" |
284243
tar xz -C $HOME/.cargo/bin
285244
286-
- name: Install llvm-tools-preview
287-
run: |
288-
rustup component add llvm-tools-preview
289-
290-
# Not necessary on a newly created image, but strictly advised
291-
- name: Run cargo clean
292-
run: |
293-
cargo clean
294-
295-
- name: Run tests
296-
env:
297-
RUSTFLAGS: "-Cinstrument-coverage"
298-
LLVM_PROFILE_FILE: "libp2p-rust-dht-%p-%m.profraw"
299-
run: |
300-
cargo test --verbose --all
301-
302-
- name: Run grcov
245+
- name: Run grcov to produce a coveralls json
303246
run: |
304247
grcov . --binary-path ./target/debug/ -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json
305248
@@ -318,7 +261,7 @@ jobs:
318261

319262
audit:
320263

321-
needs: [code-coverage, weighted-code-coverage]
264+
needs: [code-coverage]
322265

323266
runs-on: ubuntu-latest
324267

@@ -348,7 +291,7 @@ jobs:
348291

349292
deny:
350293

351-
needs: [code-coverage, weighted-code-coverage]
294+
needs: [code-coverage]
352295

353296
runs-on: ubuntu-latest
354297

@@ -394,7 +337,7 @@ jobs:
394337
395338
udeps:
396339

397-
needs: [code-coverage, weighted-code-coverage]
340+
needs: [code-coverage]
398341

399342
runs-on: ubuntu-latest
400343

dht-cache/src/cache.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,22 @@ impl Builder {
7878
pub struct Cache {
7979
peer_id: String,
8080
local: LocalCache,
81+
peers: Arc<RwLock<PeersState>>,
8182
cmd: UnboundedSender<Command>,
8283
}
8384

85+
/// Information regarding the known peers
86+
pub struct PeerInfo {
87+
/// libp2p Identifier
88+
pub peer_id: String,
89+
/// Hash of its cache of the DHT
90+
pub hash: u64,
91+
/// Last time the peer updated its state
92+
///
93+
/// TODO: use a better type
94+
pub last_seen: u128,
95+
}
96+
8497
impl Cache {
8598
/// Send a volatile message
8699
///
@@ -142,6 +155,11 @@ impl Cache {
142155
pub fn query(&self, topic: &str) -> Query {
143156
self.local.query(topic)
144157
}
158+
159+
/// Get a list of the current peers
160+
pub async fn peers(&self) -> Vec<PeerInfo> {
161+
todo!()
162+
}
145163
}
146164

147165
#[derive(Default, Debug, Clone)]
@@ -202,18 +220,19 @@ pub fn cache_channel(
202220

203221
let (cmd, r, _j) = dht_channel(swarm);
204222

223+
let peers_state = Arc::new(RwLock::new(PeersState::with_interval(
224+
resend_interval as u128,
225+
)));
226+
205227
let cache = Cache {
228+
peers: peers_state.clone(),
206229
local: local.clone(),
207230
cmd: cmd.clone(),
208231
peer_id: local_peer_id.clone(),
209232
};
210233

211234
let stream = UnboundedReceiverStream::new(r);
212235

213-
let peers_state = Arc::new(RwLock::new(PeersState::with_interval(
214-
resend_interval as u128,
215-
)));
216-
217236
let local_read = local.clone();
218237
let cmd_update = cmd.clone();
219238
let peer_id = local_peer_id.clone();

0 commit comments

Comments
 (0)