Skip to content

Commit

Permalink
Restore integration tests (#2307)
Browse files Browse the repository at this point in the history
* fix integration tests

* fix parallel test integration test

* update changelog

* update worker version in test
  • Loading branch information
midigofrank authored Jul 19, 2024
1 parent 0acda90 commit 9cd1405
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to

### Changed

- Enable End to End Integration tests
[#2187](https://github.com/OpenFn/lightning/issues/2187)

### Fixed

- Fix work order URL in failure alerts
Expand Down
17 changes: 17 additions & 0 deletions test/integration/cli_deploy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ defmodule Lightning.CliDeployTest do
require Logger

import Lightning.Factories
import Mox

alias Lightning.Accounts

@cli_path Application.app_dir(:lightning, "priv/openfn/bin/openfn")

@moduletag tmp_dir: true, integration: true

setup :set_mox_from_context
setup :verify_on_exit!

setup do
Mox.stub_with(Lightning.MockConfig, Lightning.Config.API)
Mox.stub_with(LightningMock, Lightning.API)
Mox.stub_with(Lightning.Tesla.Mock, Tesla.Adapter.Hackney)

Mox.stub_with(
Lightning.Extensions.MockUsageLimiter,
Lightning.Extensions.UsageLimiter
)

:ok
end

describe "The openfn CLI can be used to" do
setup %{tmp_dir: tmp_dir} do
url = LightningWeb.Endpoint.url()
Expand Down
36 changes: 30 additions & 6 deletions test/integration/web_and_worker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Lightning.WebAndWorkerTest do

import Lightning.JobsFixtures
import Lightning.Factories
import Mox

alias Lightning.Run
alias Lightning.Runs
Expand All @@ -15,7 +16,19 @@ defmodule Lightning.WebAndWorkerTest do

require Run

setup :set_mox_from_context
setup :verify_on_exit!

setup_all context do
Mox.stub_with(Lightning.MockConfig, Lightning.Config.API)
Mox.stub_with(LightningMock, Lightning.API)
Mox.stub_with(Lightning.Tesla.Mock, Tesla.Adapter.Hackney)

Mox.stub_with(
Lightning.Extensions.MockUsageLimiter,
Lightning.Extensions.UsageLimiter
)

start_runtime_manager(context)
end

Expand All @@ -29,9 +42,17 @@ defmodule Lightning.WebAndWorkerTest do
} do
project = insert(:project)

%{triggers: [%{id: webhook_trigger_id}]} =
%{triggers: [%{id: webhook_trigger_id}], edges: edges} =
insert(:complex_workflow, project: project)

# ensure the workflow has parallel jobs. Eliminate the branching edge
branching_edge =
Enum.find(edges, fn edge -> edge.condition_type == :on_job_failure end)

branching_edge
|> Ecto.Changeset.change(%{condition_type: :on_job_success})
|> Repo.update!()

# Post to webhook
webhook_body = %{"x" => 1}
conn = post(conn, "/i/#{webhook_trigger_id}", webhook_body)
Expand Down Expand Up @@ -218,13 +239,16 @@ defmodule Lightning.WebAndWorkerTest do
&(&1.source == "R/T" and &1.message =~ "Operation 1 complete in")
)

version_logs =
lines
|> Enum.find(fn l -> l.source == "VER" end)
|> Map.get(:message)
{:ok, version_logs} =
Repo.transaction(fn ->
run
|> Runs.get_log_lines()
|> Enum.find(fn l -> l.source == "VER" end)
|> Map.get(:message)
end)

assert version_logs =~ "▸ node.js 18.17"
assert version_logs =~ "▸ worker 1.1"
assert version_logs =~ "▸ worker 1.3"
assert version_logs =~ "▸ @openfn/language-http 3.1.12"

expected_lines =
Expand Down
5 changes: 1 addition & 4 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ Mimic.copy(Mix.Tasks.Lightning.InstallSchemas)
# Other ExUnit configuration can be found in `config/runtime.exs`,
# for example to change the `assert_receive` timeout, configure it using the
# `ASSERT_RECEIVE_TIMEOUT` environment variable.
ExUnit.configure(
formatters: [JUnitFormatter, ExUnit.CLIFormatter],
exclude: [:integration]
)
ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter])

Mox.defmock(Lightning.Extensions.MockRateLimiter,
for: Lightning.Extensions.RateLimiting
Expand Down

0 comments on commit 9cd1405

Please sign in to comment.