Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions zebra/lib/zebra/apis/internal_task_api/schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ defmodule Zebra.Apis.InternalTaskApi.Schedule do
end

defp find_max_and_default_job_time_limits(org_id) do
if org_verified?(org_id) do
{max_limit, default_limit} = find_feature_based_job_time_limits(org_id)

if org_verified?(org_id) and max_limit < @max_job_execution_time_limit do
{@max_job_execution_time_limit, @default_job_execution_time_limit}
else
find_feature_based_job_time_limits(org_id)
{max_limit, default_limit}
end
end

Expand Down
16 changes: 12 additions & 4 deletions zebra/test/support/stubbed_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@ defmodule Support.StubbedProvider do
def e1_to_f1_org_id, do: @e1_to_f1_org_id
def e2_to_f1_org_id, do: @e2_to_f1_org_id

defp max_job_time_limit_feature("enabled_30") do
defp max_job_time_limit_feature("org_30min_limit_valid_request") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}])
end

defp max_job_time_limit_feature("enabled_30_verified") do
defp max_job_time_limit_feature("org_30min_limit_invalid_request") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}])
end

defp max_job_time_limit_feature("enabled_30_unverified") do
defp max_job_time_limit_feature("org_30min_limit_verified") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}])
end

defp max_job_time_limit_feature("enabled_48h") do
defp max_job_time_limit_feature("org_30min_limit_unverified") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}])
end

defp max_job_time_limit_feature("org_48h_limit_invalid_request") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}])
end

defp max_job_time_limit_feature("org_48h_limit_verified") do
feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}])
end

Expand Down
75 changes: 69 additions & 6 deletions zebra/test/zebra/apis/internal_task_api/schedule_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,42 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
end

test "when feature is enabled and limit from request is valid => returns limit from request in seconds" do
org_id = "enabled_30"
org_id = "org_30min_limit_valid_request"

Cachex.clear(:zebra_cache)

GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ ->
InternalApi.Organization.DescribeResponse.new(
status:
InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)),
organization:
InternalApi.Organization.Organization.new(
org_username: "unverified-org",
verified: false
)
)
end)

# requested limit is less then feature limit of 30 minutes
assert 15 * 60 == Schedule.configure_execution_time_limit(org_id, 15)
end

test "when feature is enabled, limit from request is invalid, and feature limit >= default limit => returns default limit" do
org_id = "enabled_48h"
org_id = "org_48h_limit_invalid_request"

Cachex.clear(:zebra_cache)

GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ ->
InternalApi.Organization.DescribeResponse.new(
status:
InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)),
organization:
InternalApi.Organization.Organization.new(
org_username: "unverified-org",
verified: false
)
)
end)

# if requested limit <= 0 and feature limit >= max limit -> configure it to default one
assert @default_job_execution_time_limit ==
Expand All @@ -189,7 +217,21 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
end

test "when feature is enabled, limit from request is invalid, and feature limit < default limit => returns feature limit" do
org_id = "enabled_30"
org_id = "org_30min_limit_invalid_request"

Cachex.clear(:zebra_cache)

GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ ->
InternalApi.Organization.DescribeResponse.new(
status:
InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)),
organization:
InternalApi.Organization.Organization.new(
org_username: "unverified-org",
verified: false
)
)
end)

# if requested limit <= 0 and feature limit < max limit -> configure it to feature limit
assert 30 * 60 == Schedule.configure_execution_time_limit(org_id, 0)
Expand All @@ -200,7 +242,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
end

test "when org is verified and feature is enabled => bypasses feature limit and uses requested limit" do
org_id = "enabled_30_verified"
org_id = "org_30min_limit_verified"

Cachex.clear(:zebra_cache)

Expand All @@ -222,7 +264,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
end

test "when org is verified and feature is enabled with invalid request => returns default limit" do
org_id = "enabled_30_verified"
org_id = "org_30min_limit_verified"

Cachex.clear(:zebra_cache)

Expand All @@ -247,7 +289,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
end

test "when org is not verified and feature is enabled => applies feature limit" do
org_id = "enabled_30_unverified"
org_id = "org_30min_limit_unverified"

Cachex.clear(:zebra_cache)

Expand All @@ -266,6 +308,27 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do
# requested limit of 180 minutes should be capped to 30 minutes by feature flag
assert 30 * 60 == Schedule.configure_execution_time_limit(org_id, 180)
end

test "when org is verified and feature extends limit beyond 24h => uses extended limit" do
org_id = "org_48h_limit_verified"

Cachex.clear(:zebra_cache)

GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ ->
InternalApi.Organization.DescribeResponse.new(
status:
InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)),
organization:
InternalApi.Organization.Organization.new(
org_username: "verified-org",
verified: true
)
)
end)

# verified org with 48h feature flag should be able to use the extended limit
assert 30 * 60 * 60 == Schedule.configure_execution_time_limit(org_id, 30 * 60)
end
end

#
Expand Down