Skip to content
代码片段 群组 项目
提交 a9fb82a2 编辑于 作者: Alper Akgun's avatar Alper Akgun
浏览文件

Merge branch 'caw-rd-skip-terminated-in-full-reconcile' into 'master'

Exclude terminated workspaces from full reconcile

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131853



Merged-by: default avatarAlper Akgun <aakgun@gitlab.com>
Approved-by: default avatarAlper Akgun <aakgun@gitlab.com>
Reviewed-by: default avatarChad Woolley <cwoolley@gitlab.com>
Co-authored-by: default avatarChad Woolley <cwoolley@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -44,6 +44,10 @@ class Workspace < ApplicationRecord
scope :by_project_ids, ->(ids) { where(project_id: ids) }
scope :with_actual_states, ->(actual_states) { where(actual_state: actual_states) }
scope :without_terminated, -> do
where.not(desired_state: RemoteDevelopment::Workspaces::States::TERMINATED)
.where.not(actual_state: RemoteDevelopment::Workspaces::States::TERMINATED)
end
scope :ordered_by_id, -> { order(:id) }
......
......@@ -39,7 +39,7 @@ def self.find(value)
# @return [ActiveRecord::Relation]
def self.generate_workspaces_to_be_returned_query(agent:, update_type:, workspaces_from_agent_infos:)
# For a FULL update, return all workspaces for the agent which exist in the database
return agent.workspaces.all if update_type == FULL
return agent.workspaces.without_terminated.all if update_type == FULL
# For a PARTIAL update, return:
# 1. Workspaces with_desired_state_updated_more_recently_than_last_response_to_agent
......
......@@ -17,6 +17,19 @@
)
end
let_it_be(:workspace_that_is_terminated, reload: true) do
create(
:workspace,
:without_realistic_after_create_timestamp_updates,
name: "workspace_that_is_terminated",
desired_state: RemoteDevelopment::Workspaces::States::TERMINATED,
actual_state: RemoteDevelopment::Workspaces::States::TERMINATED,
agent: agent,
user: user,
responded_to_agent_at: 2.hours.ago
)
end
let_it_be(:workspace_from_agent_info, reload: true) do
create(
:workspace,
......@@ -64,6 +77,12 @@
workspace_only_returned_by_full_update.responded_to_agent_at - 1.hour
)
# desired_state_updated_at IS NOT more recent than responded_to_agent_at
workspace_that_is_terminated.update_attribute(
:desired_state_updated_at,
workspace_that_is_terminated.responded_to_agent_at - 1.hour
)
# desired_state_updated_at IS NOT more recent than responded_to_agent_at
workspace_from_agent_info.update_attribute(
:desired_state_updated_at,
......@@ -86,6 +105,8 @@
it "has the expected fixtures" do
expect(workspace_only_returned_by_full_update.desired_state_updated_at)
.to be < workspace_only_returned_by_full_update.responded_to_agent_at
expect(workspace_that_is_terminated.desired_state_updated_at)
.to be < workspace_that_is_terminated.responded_to_agent_at
expect(workspace_with_new_update_to_desired_state.desired_state_updated_at)
.to be > workspace_with_new_update_to_desired_state.responded_to_agent_at
expect(workspace_from_agent_info.desired_state_updated_at)
......@@ -106,10 +127,13 @@
]
end
it "returns all workspaces" do
it "does not return terminated workspaces" do
expect(subject.fetch(:workspaces_to_be_returned).map(&:name)).not_to include(workspace_that_is_terminated.name)
end
it "returns all non-terminated workspaces" do
expect(subject.fetch(:workspaces_to_be_returned).map(&:name))
.to match_array(expected_workspaces_to_be_returned.map(&:name))
expect(subject).to match(hash_including(value))
end
it "preserves existing value entries",
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册