Ad
  • Custom User Avatar

    Not an issue.

  • Custom User Avatar

    You're welcome, and I hope that despite of all the problems, you like it ;)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Aside from some "smaller" problems which might or might not make your solution to fail because of some subtle timing bugs and race conditions, there are two main problems which make you fail. I will try to hint you a bit without giving out too much ;)

    First of all, try following test case:

    	@Test
    	public void testFailed() throws InterruptedException {
    		
    		List<Runnable> tasks = new ArrayList<>();
    		Set<Runnable> expectedFailed = new HashSet<>();
    		
    		expectedFailed.add(factory.createFailingTask(6000));
    		expectedFailed.add(factory.createFailingTask(6000));
    		expectedFailed.add(factory.createFailingTask(6000));
    		expectedFailed.add(factory.createFailingTask(6000));
    				
    		tasks.addAll(expectedFailed);
    		
    		Worker.ExecutedTasks result = worker.execute(tasks, DEFAULT_TIMEOUT);
    		
    		Assert.assertTrue(result.successful.isEmpty());
    		Assert.assertEquals(expectedFailed, result.failed);
    		Assert.assertTrue(result.timedOut.isEmpty());
    	}
    

    It should run 4 tasks and finish after 6 seconds, but with your solution, following happens:

    Started Task-1
    Started Task-4
    Started Task-2
    Started Task-3
    Scheduled at: 1531224197472
    Task-1 registered as failed.
    Task-4 registered as failed.
    Task-2 registered as failed.
    Scheduler runs at: 1531224207473
    Task unexpectedly interrupted after approx. 4s.
    

    For some reason (which I know, and you have to find out) three tasks are scheduled, executed, and categorized properly, but fourth task is not. Find out why, and you are half way there ;)

    This and another problem you can diagnose by comparing execution logs of my and yours solution:

    Yours:

    Started Task-32
    Started Task-17
    Task [Task-17] going to work for 3700ms.
    Started Task-22
    Started Task-21
    Started Task-9
    
    ... snip ...
    
    Started Task-8
    Started Task-18
    Started Task-20
    Started Task-28
    Started Task-10
    Scheduled at: 1531223321111
    Task-22 registered as failed.
    Task [Task-21] going to work for 4500ms.
    Task [Task-17] exited after approx. 3700ms.
    Task-17 registered as successful.
    Task [Task-9] going to work for 2100ms.
    Task [Task-21] exited after approx. 4500ms.
    
    ... snip ...
    
    Task [Task-14] exited after approx. 3100ms.
    Task-14 registered as successful.
    Task [Task-3] going to work for 900ms.
    Task [Task-18] exited after approx. 3901ms.
    Task-18 registered as successful.
    Scheduler runs at: 1531223331111
    Task unexpectedly interrupted.
    Task [Task-3] exited after approx. 380ms.
    Task interrupted after approx. 0s.
    Task interrupted after approx. 10s.
    

    Mine:

    Submitted task Task-41
    Submitted task Task-13
    Submitted task Task-5
    Task [Task-13] going to work for 2900ms.
    Task [Task-5] going to work for 1300ms.
    Submitted task Task-35
    Submitted task Task-29
    Task [Task-29] going to work for 6100ms.
    Submitted task Task-43
    Submitted task Task-2
    Task [Task-2] going to work for 700ms.
    Submitted task Task-18
    Task [Task-18] going to work for 3900ms.
    
    .... snip ....
    
    Task [Task-27] exited after approx. 5700ms.
    Successful task Task-27 recorded.
    Task [Task-28] exited after approx. 5900ms.
    Successful task Task-28 recorded.
    Task [Task-29] exited after approx. 6100ms.
    Successful task Task-29 recorded.
    Task [Task-30] exited after approx. 6300ms.
    Successful task Task-30 recorded.
    

    One problem manifests at the top of your log, and the second one - near the bottom. I won't say more to not make things too easy, but I assure you that the cause of failing tests is in your code, and not in the tests. And both problems are strictly concurrency related, and not just some stupid mistakes, so I believe that when you finally find them, you will learn a lot (the first problem is almost identical to a gotcha which applies to C# solutions if they use default configuration of concurrency API). I even managed to fix the problems in your solution (modified one line, added a few) and it passed!

    Good luck, and please come back with fresh ideas and try again!

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You can also try to remove all test cases except one from the sample tests and see if it behaves in expected way. For example, one of the test cases gives following result with your solution:

    Test Results:
     BasicTest
     testNoExcessiveWait
    Execution time significantly exceeded time necessary for execution of all tasks. Execution took 10022ms, while 700ms is more than enough.
    

    With my solution, and two solutions of other users, tests pass and that's why I am inclined towards opinion that your solution does not fulfill requirements related to waiting times.

    Keep trying, and good luck!

  • Custom User Avatar

    I can check it when I get home but remember that whole test suite must run below 16 seconds, and not just one test method. did you try to run all basic tests locally at once? how long did they run? was it less than 16 seconds?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Check following scenario: create ten actions, each of them sleeping for 8 seconds, and check how long does it take on your local environment? Remember that CodeWars timeouts all Java solutions that take more than 16 seconds.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    @Padmanarayanan: Did you print the input to verify the output yourself? I just passed the tests, and it worked ok.

    If you still believe there's an issue with the tests, post your code (+ the test input) in reply and mark it as a spoiler.
    That's going to be help pin down the issue quickly.

  • Custom User Avatar

    console.log(braces)

  • Default User Avatar

    JavaScript:

    I'm able to pass the 5 test cases provided, however I'm still failing test cases: 8, 10, 11 and 14. Is there not a way to see the inputs for these test cases?

  • Default User Avatar

    Java unit tests are not working as intended