Facing error while testing the file

hey all I am trying to write a cron job that delete some queried data from redis, I have already created a list of all the redis keys I need to delete. and have implemented redis delete but while testing whether it is deleted or not it is showing that is not deleted.
my code is -

      Query
      |> Repo.all()
      |> Enum.each(fn x ->
        create_keys_for_redis(x)
        |> Enum.join(" ")
        |> MultiNodeRedisClient.delete!()
      end)

here for every query there are many keys associated to that so create_keys_for_redis function create all the required keys and pass them for deletion.

the test file where I am testing whether it is deleted or not is -

test "should delete keys associated with old campaigns from redis" do
      today =
        Timex.now(@timezone)
        |> DateTime.to_date()

      campaign_1 =
        insert(:campaign, %{
          start_date: Timex.shift(today, days: -200),
          end_date: Timex.shift(today, days: -182)
        })

      campaign_2 =
        insert(:campaign, %{
          start_date: Timex.shift(today, days: -240),
          end_date: Timex.shift(today, days: -239)
        })

      campaign_3 =
        insert(:campaign, %{
          start_date: Timex.shift(today, days: -200),
          end_date: Timex.shift(today, days: -189)
        })

      campaign_4 =
        insert(:campaign, %{
          start_date: Timex.shift(today, days: -200),
          end_date: Timex.shift(today, days: -199)
        })

     [campaign_1, campaign_2, campaign_3, campaign_4]
        |> Enum.each(fn campaign -> populate_redis_keys(campaign) end)

      CampaignArchivalScheduler.perform(%{})  # it runs my cron job where it deletes all the keys from redis

      [campaign_1, campaign_2, campaign_3, campaign_4]
      |> Enum.each(fn campaign ->
        CampaignArchivalScheduler.create_keys_for_redis(campaign)
        |> Enum.each(fn key ->
          assert MultiNodeRedisClient.exists?(campaign.id, key) == false
        end)
      end)
    end

  defp populate_redis_keys(campaign) do
    CampaignArchivalScheduler.create_keys_for_redis(campaign)
    |> Enum.map(fn x -> MultiNodeRedisClient.command(:setnx,[x, "12"]) end)
    |> inpipeline(campaign.id)
  end

  defp inpipeline(commands, id) do
    MultiNodeRedisClient.pipeline(id, commands)
  end

the error I am getting is -

test perform should delete keys associated with old campaigns from redis (CampaignManager.CampaignArchivalSchedulerTest)
     test/campaign_manager/workers/campaign_archival_scheduler_test.exs:75
     Assertion with == failed
     code:  assert MultiNodeRedisClient.exists?(campaign.id, key) == 0
     left:  true
     right: 0
     stacktrace:
       (elixir 1.11.2) lib/enum.ex:786: Enum."-each/2-lists^foreach/1-0-"/2
       (elixir 1.11.2) lib/enum.ex:786: Enum.each/2
       (elixir 1.11.2) lib/enum.ex:786: Enum."-each/2-lists^foreach/1-0-"/2
       (elixir 1.11.2) lib/enum.ex:786: Enum.each/2
       test/campaign_manager/workers/campaign_archival_scheduler_test.exs:110: (test)



Finished in 0.5 seconds
3 tests, 1 failure, 2 excluded

what mistake have i committed and how should i correct it.

is your job being performed by another process? if so it is happening async with your test and you may need to sleep for a period to allow the process to perform its work. if you can isolate that work to a function that you can call directly from your test then that may make it more testable