Skip to content

Commit ddb2f6f

Browse files
committed
Merge branch 'master' into eliza/no-clone-global-dispatch
2 parents 6da22e5 + 4707e6f commit ddb2f6f

File tree

1 file changed

+67
-16
lines changed

1 file changed

+67
-16
lines changed

tracing-core/src/callsite.rs

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,11 @@ impl LinkedList {
336336
mod tests {
337337
use super::*;
338338

339-
#[derive(Eq, PartialEq)]
340-
struct Cs1;
341-
static CS1: Cs1 = Cs1;
342-
static REG1: Registration = Registration::new(&CS1);
339+
struct TestCallsite;
340+
static CS1: TestCallsite = TestCallsite;
341+
static CS2: TestCallsite = TestCallsite;
343342

344-
impl Callsite for Cs1 {
345-
fn set_interest(&self, _interest: Interest) {}
346-
fn metadata(&self) -> &Metadata<'_> {
347-
unimplemented!("not needed for this test")
348-
}
349-
}
350-
351-
struct Cs2;
352-
static CS2: Cs2 = Cs2;
353-
static REG2: Registration = Registration::new(&CS2);
354-
355-
impl Callsite for Cs2 {
343+
impl Callsite for TestCallsite {
356344
fn set_interest(&self, _interest: Interest) {}
357345
fn metadata(&self) -> &Metadata<'_> {
358346
unimplemented!("not needed for this test")
@@ -361,6 +349,9 @@ mod tests {
361349

362350
#[test]
363351
fn linked_list_push() {
352+
static REG1: Registration = Registration::new(&CS1);
353+
static REG2: Registration = Registration::new(&CS2);
354+
364355
let linked_list = LinkedList::new();
365356

366357
linked_list.push(&REG1);
@@ -385,9 +376,69 @@ mod tests {
385376
});
386377
}
387378

379+
#[test]
380+
fn linked_list_push_several() {
381+
static REG1: Registration = Registration::new(&CS1);
382+
static REG2: Registration = Registration::new(&CS2);
383+
static REG3: Registration = Registration::new(&CS1);
384+
static REG4: Registration = Registration::new(&CS2);
385+
386+
let linked_list = LinkedList::new();
387+
388+
fn expect<'a>(
389+
callsites: &'a mut impl Iterator<Item = &'static Registration>,
390+
) -> impl FnMut(&'static Registration) + 'a {
391+
move |reg: &'static Registration| {
392+
let ptr = callsites
393+
.next()
394+
.expect("list contained more than the expected number of registrations!");
395+
396+
assert!(
397+
ptr::eq(reg, ptr),
398+
"Registration pointers need to match ({:?} != {:?})",
399+
reg,
400+
ptr
401+
);
402+
}
403+
}
404+
405+
linked_list.push(&REG1);
406+
linked_list.push(&REG2);
407+
let regs = [&REG2, &REG1];
408+
let mut callsites = regs.iter().copied();
409+
linked_list.for_each(expect(&mut callsites));
410+
assert!(
411+
callsites.next().is_none(),
412+
"some registrations were expected but not present: {:?}",
413+
callsites
414+
);
415+
416+
linked_list.push(&REG3);
417+
let regs = [&REG3, &REG2, &REG1];
418+
let mut callsites = regs.iter().copied();
419+
linked_list.for_each(expect(&mut callsites));
420+
assert!(
421+
callsites.next().is_none(),
422+
"some registrations were expected but not present: {:?}",
423+
callsites
424+
);
425+
426+
linked_list.push(&REG4);
427+
let regs = [&REG4, &REG3, &REG2, &REG1];
428+
let mut callsites = regs.iter().copied();
429+
linked_list.for_each(expect(&mut callsites));
430+
assert!(
431+
callsites.next().is_none(),
432+
"some registrations were expected but not present: {:?}",
433+
callsites
434+
);
435+
}
436+
388437
#[test]
389438
#[should_panic]
390439
fn linked_list_repeated() {
440+
static REG1: Registration = Registration::new(&CS1);
441+
391442
let linked_list = LinkedList::new();
392443

393444
linked_list.push(&REG1);

0 commit comments

Comments
 (0)