Skip to content

Commit

Permalink
Merge pull request #492 from evo-lua/etrace-notify-fix
Browse files Browse the repository at this point in the history
Prevent event notifications from being suppressed if logging for the given event happens to be disabled
  • Loading branch information
Duckwhale committed Feb 9, 2024
2 parents a9212d4 + 62b3c02 commit ba5c5db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 0 additions & 5 deletions Runtime/Libraries/etrace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ function etrace.notify(event, payload)
return
end

local isEventEnabled = (etrace.registeredEvents[event] == true)
if not isEventEnabled then
return
end

for listener, eventHandler in pairs(subscribers) do
if type(listener) == "table" then -- Enable use of : syntax
eventHandler(listener, event, payload)
Expand Down
14 changes: 10 additions & 4 deletions Tests/BDD/etrace-library.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -715,17 +715,19 @@ describe("etrace", function()
assertEquals(providedArguments.functionListener, { "MEEP", {} })
end)

it("should have no effect if the given event is disabled", function()
it("should still work if logging for the given event is disabled", function()
local providedArguments = {}

local function functionListener(event, payload)
providedArguments.functionListener = { event, payload }
end

etrace.register("MEEP")
etrace.disable("MEEP")
etrace.subscribe("MEEP", functionListener)
etrace.notify("MEEP", { hello = 42 })
assertEquals(providedArguments.functionListener, nil)
assertEquals(providedArguments.functionListener[1], "MEEP")
assertEquals(providedArguments.functionListener[2].hello, 42)
end)
end)

Expand Down Expand Up @@ -777,7 +779,7 @@ describe("etrace", function()
assertEquals(providedArguments.functionListener, { "MEEP", { hello = 42 } })
end)

it("should have no effect if the given event is disabled", function()
it("should still work if logging for the given event is disabled", function()
local providedArguments = {}

local function functionListener(event, payload)
Expand All @@ -787,7 +789,11 @@ describe("etrace", function()
etrace.register("MEEP")
etrace.subscribe("MEEP", functionListener)
etrace.publish("MEEP", { hello = 42 })
assertEquals(providedArguments.functionListener, nil)
-- Disabling event notifications would break any listener relying on the event system
assertEquals(providedArguments.functionListener[1], "MEEP")
assertEquals(providedArguments.functionListener[2].hello, 42)

-- The log should be empty, however as logging was indeed disabled
assertEquals(etrace.filter(), {})
end)
end)
Expand Down

0 comments on commit ba5c5db

Please sign in to comment.