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 client list, fix channel race, hjoin, tests #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kdedon
Copy link
Contributor

@kdedon kdedon commented Jul 20, 2023

Fixed a bug with hjoin, username tests to include the @, and removed the test for a number as the first character due to that being an unnecessary check after testing for the @ above.

I handled the two TODOs:
Add after the remove is handled by just writing the channel back into the global index. There is still a race condition where a user could /join during the time that the channel was deleted but while the add was still queued, so it is not completely fixed; I think it might be safest to just use a regular map and use an RWLock Mutex for any possible operation.

I added a client channel slice. I liberally used appends, so not sure how much of an optimization it actually was.

@@ -71,3 +83,68 @@ func TestClient(t *testing.T) {

}
}

// TestMultipleClients
Copy link
Contributor Author

@kdedon kdedon Jul 21, 2023

Choose a reason for hiding this comment

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

These test cases tend to deadlock and need to be redesigned.

Edit: Fixed the test. The pipe acts like an unbuffered channel and blocks until the data is read. I modified the test handling to read from all the clients at once in different goroutines and then handle them sequentially once they had been collated. I also modified it to fully read everything before moving on to make it easier to debug/create tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the code is valuable, I think the your code to solve this issue is too complex. I need some time to think about it.

Could you do a PR for the testing only? This is something I'm happy to apply.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where did we leave off on this? @kdedon did you intend to break this into 2 pieces? I hate to have this dangling out here for so long.

}

func (c *Client) String() string {
return c.Name
}

func newClient(conn *net.TCPConn) *Client {
func newClient(conn net.Conn) *Client {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change makes it much easier to build tests since the entire server doesn't have to be constructed.

@kdedon kdedon marked this pull request as ready for review July 22, 2023 05:09
@mozzwald mozzwald requested a review from rogersm August 16, 2023 16:00
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.

3 participants