Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshots test #18

Merged
merged 19 commits into from
Feb 25, 2024
Merged

Snapshots test #18

merged 19 commits into from
Feb 25, 2024

Conversation

zhirafovod
Copy link
Member

Description

  • Test to snapshot and recover workflow
  • PulsarMock to test in-memory subscribePulsar

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@zhirafovod zhirafovod requested a review from a team as a code owner February 23, 2024 18:49
example/rebelCommunication.yaml Outdated Show resolved Hide resolved
example/rebelCommunication.yaml Show resolved Hide resolved
src/test/PulsarMock.js Outdated Show resolved Hide resolved
src/test/PulsarMock.js Show resolved Hide resolved
src/test/PulsarMock.js Show resolved Hide resolved
Copy link
Contributor

@geoffhendrey geoffhendrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was much easier to understand. I left a few suggestions that you can take or leave. Not critical.

@@ -0,0 +1,251 @@
export class PulsarClientMock {
// A map used to simulate an in-memory store for messages. The keys are topic names, and the values are arrays of message objects.
static inMemoryStore = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with all these being static, it will not be possible to run more than one test client on a given system. I am not sure that is a good idea ... perhaps good enough for now, but prolly worth the small refactor to make then instance fields

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big, but a feature - I want the data to persist client instance restart, so we can demonstrate how server side acks work

// A map where keys are topic names and values are arrays of receive function invocations (listeners). These listeners are called to notify about new messages.
static listeners = new Map();

// The default time in milliseconds to wait before a message is considered not acknowledged (acknowledged messages are removed from visibility to simulate message acknowledgment behavior).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do ack's need timeouts? Is that something pulsar-like that we are trying to simulate? What is the concept of "visibility"?

send: async (message) => {
const messageId = new MessageId(`message-${++PulsarClientMock.messageIdCounter}`);
const messageInstance = new Message(topic, undefined, message.data, messageId, Date.now(), Date.now(), 0, '');
const messages = PulsarClientMock.inMemoryStore.get(topic) || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the || [] will result in a phantom topic that is not tracked anywhere

/**
* receives either returns the next visible message, or blocks until a message is available.
*/
receive: () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we don't have TS to declare return type is promise, marking this method async may be a good idea for documenting that it returns a Promise

return new Promise((resolve) => {
const tryResolve = () => {
const messages = PulsarClientMock.inMemoryStore.get(topic) || [];
const messageIndex = messages.findIndex(m => !m.subscriberIds.has(subscriberId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use .find() here instead of findIndex

@zhirafovod zhirafovod merged commit 2a7f8b5 into main Feb 25, 2024
1 check passed
@zhirafovod zhirafovod deleted the snapshots_test branch February 25, 2024 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants