Stash State Cleanup

- 1 min read

When game processes recover stashed game state from the CRDT store, the state is not removed. This is not ideal as this stash will continue to grow over time and use up memory. I need to make a simple change to clean up stashed state once it’s been handed off to a new process.

I add a new test case to assert the desired behavior.

  describe "pickup/1 when state is stashed for key" do
    setup [:stash_state]

    test "should return stashed value", ctx do
      assert ctx.stashed_value == StateHandoff.pickup(ctx.stashed_key)
    end

    test "should return nil for key on subsequent call", ctx do
      StateHandoff.pickup(ctx.stashed_key)

      assert nil == StateHandoff.pickup(ctx.stashed_key)
    end
  end

I add a single line with DeltaCRDT.delete to the pickup handler in the StateHandoff GenServer to make the test pass.

That’s all for now. I just wanted to check off a smaller item on my to-do list in the short time I have today.