{"action":"created","issue":{"url":"https://api.github.com/repos/fmi/java-course/issues/40","repository_url":"https://api.github.com/repos/fmi/java-course","labels_url":"https://api.github.com/repos/fmi/java-course/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/fmi/java-course/issues/40/comments","events_url":"https://api.github.com/repos/fmi/java-course/issues/40/events","html_url":"https://github.com/fmi/java-course/issues/40","id":393600155,"node_id":"MDU6SXNzdWUzOTM2MDAxNTU=","number":40,"title":"Race condition in 09-network's tests","user":{"login":"stainlesspot","id":17738549,"node_id":"MDQ6VXNlcjE3NzM4NTQ5","avatar_url":"https://avatars1.githubusercontent.com/u/17738549?v=4","gravatar_id":"","url":"https://api.github.com/users/stainlesspot","html_url":"https://github.com/stainlesspot","followers_url":"https://api.github.com/users/stainlesspot/followers","following_url":"https://api.github.com/users/stainlesspot/following{/other_user}","gists_url":"https://api.github.com/users/stainlesspot/gists{/gist_id}","starred_url":"https://api.github.com/users/stainlesspot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stainlesspot/subscriptions","organizations_url":"https://api.github.com/users/stainlesspot/orgs","repos_url":"https://api.github.com/users/stainlesspot/repos","events_url":"https://api.github.com/users/stainlesspot/events{/privacy}","received_events_url":"https://api.github.com/users/stainlesspot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-21T21:49:50Z","updated_at":"2018-12-21T22:05:36Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Several runs on the given tests in [09-network](https://github.com/fmi/java-course/blob/master/09-network/lab/test/bg/sofia/uni/fmi/java/network/server/nio/CommandExecutionServerTest.java) reveal that (randomly) some of them sometimes fail and sometimes don't.\r\nI suspect the problem comes from the fact that the server is on a different thread, thus a test may try to connect to the server before it has started.\r\n\r\nThe solution would be making each test wait for the server untill it has started. But I fail to find a painless and elegant way to do this in the current setup. How could this problem be fixed? "},"comment":{"url":"https://api.github.com/repos/fmi/java-course/issues/comments/449509940","html_url":"https://github.com/fmi/java-course/issues/40#issuecomment-449509940","issue_url":"https://api.github.com/repos/fmi/java-course/issues/40","id":449509940,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTUwOTk0MA==","user":{"login":"stainlesspot","id":17738549,"node_id":"MDQ6VXNlcjE3NzM4NTQ5","avatar_url":"https://avatars1.githubusercontent.com/u/17738549?v=4","gravatar_id":"","url":"https://api.github.com/users/stainlesspot","html_url":"https://github.com/stainlesspot","followers_url":"https://api.github.com/users/stainlesspot/followers","following_url":"https://api.github.com/users/stainlesspot/following{/other_user}","gists_url":"https://api.github.com/users/stainlesspot/gists{/gist_id}","starred_url":"https://api.github.com/users/stainlesspot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stainlesspot/subscriptions","organizations_url":"https://api.github.com/users/stainlesspot/orgs","repos_url":"https://api.github.com/users/stainlesspot/repos","events_url":"https://api.github.com/users/stainlesspot/events{/privacy}","received_events_url":"https://api.github.com/users/stainlesspot/received_events","type":"User","site_admin":false},"created_at":"2018-12-21T22:05:36Z","updated_at":"2018-12-21T22:05:36Z","author_association":"CONTRIBUTOR","body":"One solution I see is to add to add a new field to `CommandExecutionServer`:\r\n```java\r\nprivate boolean started = false;\r\n```\r\nwhich is updated to true when the server actually starts.\r\n\r\nAnd a new method to `CommandExecutionServer`:\r\n```java\r\npublic void started() {\r\n    while (!started) {\r\n        Thread.sleep(200);\r\n   }\r\n}\r\n```\r\nAnd then in the tests:\r\n```java\r\n@Before\r\npublic void waitForServer() {\r\n    commandExServer.started();\r\n}\r\n```\r\n\r\nBut I would prefferably avoid `Thread.sleep`."}}
{"actor":{"display_login":"stainlesspot"}}