Skip to content

Commit

Permalink
refactor(experimental): wrap subscription tests in try...finally (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec authored Dec 20, 2023
1 parent e1b2277 commit a1fafee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ describe('slotNotifications', () => {
it('produces slot notifications', async () => {
expect.assertions(1);
const abortController = new AbortController();
const slotNotifications = await rpc.slotNotifications().subscribe({ abortSignal: abortController.signal });
const iterator = slotNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty('value', {
parent: expect.any(BigInt),
root: expect.any(BigInt),
slot: expect.any(BigInt),
});
abortController.abort();
try {
const slotNotifications = await rpc.slotNotifications().subscribe({ abortSignal: abortController.signal });
const iterator = slotNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty('value', {
parent: expect.any(BigInt),
root: expect.any(BigInt),
slot: expect.any(BigInt),
});
} finally {
abortController.abort();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ describe('slotsUpdatesNotifications', () => {
it('produces slots updates notifications', async () => {
expect.assertions(1);
const abortController = new AbortController();
const slotsUpdatesNotifications = await rpc
.slotsUpdatesNotifications()
.subscribe({ abortSignal: abortController.signal });
const iterator = slotsUpdatesNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty(
'value',
expect.objectContaining({
slot: expect.any(BigInt),
timestamp: expect.any(BigInt),
type: expect.any(String),
}),
);
abortController.abort();
try {
const slotsUpdatesNotifications = await rpc
.slotsUpdatesNotifications()
.subscribe({ abortSignal: abortController.signal });
const iterator = slotsUpdatesNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty(
'value',
expect.objectContaining({
slot: expect.any(BigInt),
timestamp: expect.any(BigInt),
type: expect.any(String),
}),
);
} finally {
abortController.abort();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ describe('voteNotifications', () => {
it('produces vote notifications', async () => {
expect.assertions(1);
const abortController = new AbortController();
const voteNotifications = await rpc.voteNotifications().subscribe({ abortSignal: abortController.signal });
const iterator = voteNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty(
'value',
expect.objectContaining({
hash: expect.any(String),
signature: expect.any(String),
slots: expect.arrayContaining([expect.any(BigInt)]),
// TODO: Test for null. It appears this is maybe non-deterministic? Seems to maybe occur on delayed votes?
timestamp: expect.any(BigInt),
votePubkey: expect.any(String),
}),
);
abortController.abort();
try {
const voteNotifications = await rpc.voteNotifications().subscribe({ abortSignal: abortController.signal });
const iterator = voteNotifications[Symbol.asyncIterator]();
await expect(iterator.next()).resolves.toHaveProperty(
'value',
expect.objectContaining({
hash: expect.any(String),
signature: expect.any(String),
slots: expect.arrayContaining([expect.any(BigInt)]),
// TODO: Test for null. It appears this is maybe non-deterministic? Seems to maybe occur on delayed votes?
timestamp: expect.any(BigInt),
votePubkey: expect.any(String),
}),
);
} finally {
abortController.abort();
}
});
});

0 comments on commit a1fafee

Please sign in to comment.