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

Add test cases for server.rs #34

Closed

Conversation

amustaque97
Copy link

Closes: #21

Changes proposed in the MR:

  • Adding mpsc::channel in server.start method to stop based on the communication as this is required for writing test case else loop will continue forever.
  • Update examples directory code snippets.
  • Adding test cases for the below methods.
  • pub async fn new(id: u32, config: ServerConfig, cluster_config: ClusterConfig) -> Server {
  • pub async fn start(&mut self, rx: Option<mpsc::Receiver<()>>) {
  • pub fn is_leader(&self) -> bool {
  • async fn follower(&mut self) {
  • async fn candidate(&mut self) {
  • async fn leader(&mut self) {
  • async fn receive_rpc(&mut self) {
  • async fn handle_rpc(&mut self, data: Vec<u8>) {
  • async fn handle_client_request(&mut self, data: Vec<u8>) {
  • async fn handle_request_vote(&mut self, data: &[u8]) {
  • async fn handle_request_vote_response(&mut self, data: &[u8]) {
  • async fn handle_append_entries(&mut self, data: Vec<u8>) {
  • async fn handle_append_entries_response(&mut self, data: &[u8]) {
  • async fn handle_heartbeat(&mut self, data: &[u8]) {
  • async fn handle_heartbeat_response(&mut self) {
  • async fn handle_repair_request(&mut self, data: &[u8]) {
  • async fn handle_repair_response(&mut self, data: &[u8]) {
  • async fn handle_join_request(&mut self, data: &[u8]) {
  • async fn handle_join_response(&mut self, data: &[u8]) {
  • async fn persist_to_disk(&mut self, id: u32, data: &[u8]) {
  • async fn stop(self) {

@@ -135,7 +137,7 @@ impl Server {
}
}

pub async fn start(&mut self) {
pub async fn start(&mut self, rx: Option<mpsc::Receiver<()>>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand this PR is still in Draft, but why do you wanna introduce a channel over here ?

Copy link
Author

Choose a reason for hiding this comment

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

Hey 👋🏻
No worries, feel free to review anytime I'm completely fine with it.

This is added because if I don't pass some sort of signal, the test case will keep running forever because of the infinite loop. I couldn't think of any better approach than this that's why I consider it optional so actual implementation/usage won't have to pass any value. I'm planning to add it in other methods too where we have an infinite loop.

I'm happy to learn some new techniques/patterns if you can share them here.

Thanks!

@dharanad dharanad added the work in progress PR is work in progress label Aug 20, 2024
@vaibhawvipul
Copy link
Contributor

any progress here?

@amustaque97
Copy link
Author

any progress here?

someone reached out on the issue and I gave my comment, not sure after that.
Here is the link to my comment.
#21 (comment)

Thanks!

@vaibhawvipul
Copy link
Contributor

closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work in progress PR is work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Unit tests for server.rs
3 participants