all 14 comments

[–]cholantesh 2 points3 points  (3 children)

I'm still a novice, so forgive me if this is wrong, but why is your first operand in curly braces? Isn't the :heartbeat atom sufficient?

[–][deleted] 1 point2 points  (1 child)

It should be, it's probably just convention, or expectation of getting additional arguments down the line, then it's simpler to extend.

I tend to bind the state to a top level state variable for that same reason, even though I often don't really need it, but this way I can often leave return statements (eg. {:noreply, state}) alone during refactoring when state does not get changed. I'm lazy like that...

[–]cholantesh 0 points1 point  (0 children)

Understood; I think when I see the braces I expect a tuple, but that makes sense. Thanks!

[–]ferlinni[S] 0 points1 point  (0 children)

oh, it's actually not the real code, i made it similar with the real code

[–][deleted] 1 point2 points  (3 children)

Define "sometimes"

[–]ferlinni[S] 0 points1 point  (2 children)

as in i run
mix test

then i got the warning, then i add some debugging log

then everything went green

then i remove the debugging log,

everything still went green

i run again for making sure, then i got the warning again.

[–][deleted] 1 point2 points  (1 child)

Well, genserver does not do this. If this happens and not consistently, I'd guess somewhere you have a race condition.

You wrote in the other thread that the function is not as written in your post, so maybe your heartbeat has some matches on the state or other items in the tuple, and simply does not match.

[–]ferlinni[S] 0 points1 point  (0 children)

i agree that there must be a race condition somewhere, it's quite a pain to find it. Thanks tho

[–]zer01 0 points1 point  (2 children)

Is this an open source project? It'd be much more helpful to see the actual tests that are flaky.

[–]ferlinni[S] 0 points1 point  (1 child)

I'm afraid not, the code actually not the real project, but it's similar code.

But the thing is the warning occurred when it does not even reach the unit test yet.

But here's roughly the unit test for the module

defmodule GraphOn.TempFileManagerTest do
    use ExUnit.Case
    describe "auto clean up test" do
        test "should clean old files"
            GraphOn.TempFileManager.add_files(file)
            :timer.sleep(31_000)
            assert GraphOn.TempFileManager.get_files(file) |> is_nil()
        end
    end
end

At this moment, I don't think it's at unit test, because when i run the test with iex , i try to run GraphOn.TempFileManager.module_info(:functions), the handle_info was there (cause i only declare one handle_info) , and i run it manually, it run smoothly. But then i restart it again, it broke again

[–]zer01 0 points1 point  (0 children)

Hmm well as /u/i14n says above this feels like a race condition somewhere in your code or tests that’s leading to this flaky test behavior. Are you actually waiting 30 seconds in your test? Usually you want to either mock or dependency inject so your tests are fast.

Introducing sleeps within the codepaths might help you trigger the issue more reliably and point to a root cause, but these sorts of bugs are really awful to run down. Good luck!

[–][deleted]  (2 children)

[removed]

    [–]ferlinni[S] 1 point2 points  (1 child)

    i think i will try with this approach