Commit 9d6fe7bf authored by Shinya Maeda's avatar Shinya Maeda

Refactoring ci_job_trace to ci_build_trace

parent 4eb67ccf
...@@ -19,14 +19,13 @@ module Ci ...@@ -19,14 +19,13 @@ module Ci
has_one :last_deployment, -> { order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment' has_one :last_deployment, -> { order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection' has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy, inverse_of: :job # rubocop:disable Cop/ActiveRecordDependent has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy, inverse_of: :job # rubocop:disable Cop/ActiveRecordDependent
has_one :job_artifacts_archive, -> { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_archive, -> { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_many :chunks, class_name: 'Ci::JobTraceChunk', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_one :metadata, class_name: 'Ci::BuildMetadata' has_one :metadata, class_name: 'Ci::BuildMetadata'
delegate :timeout, to: :metadata, prefix: true, allow_nil: true delegate :timeout, to: :metadata, prefix: true, allow_nil: true
delegate :gitlab_deploy_token, to: :project delegate :gitlab_deploy_token, to: :project
......
module Ci module Ci
class JobTraceChunk < ActiveRecord::Base class BuildTraceChunk < ActiveRecord::Base
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id belongs_to :build, class_name: "Ci::Build", foreign_key: :build_id
after_destroy :redis_delete_data, if: :redis? after_destroy :redis_delete_data, if: :redis?
...@@ -118,11 +118,11 @@ module Ci ...@@ -118,11 +118,11 @@ module Ci
end end
def redis_data_key def redis_data_key
"gitlab:ci:trace:#{job_id}:chunks:#{chunk_index}:data" "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}:data"
end end
def redis_lock_key def redis_lock_key
"gitlab:ci:trace:#{job_id}:chunks:#{chunk_index}:lock" "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}:lock"
end end
def in_lock def in_lock
......
...@@ -4,9 +4,9 @@ class BuildTraceSwapChunkWorker ...@@ -4,9 +4,9 @@ class BuildTraceSwapChunkWorker
queue_namespace :pipeline_processing queue_namespace :pipeline_processing
def perform(job_trace_chunk_id) def perform(build_trace_chunk_id)
Ci::JobTraceChunk.find_by(id: job_trace_chunk_id).try do |job_trace_chunk| Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk|
job_trace_chunk.use_database! build_trace_chunk.use_database!
end end
end end
end end
class CreateCiJobTraceChunks < ActiveRecord::Migration class CreateCiBuildTraceChunks < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
def change def change
create_table :ci_job_trace_chunks, id: :bigserial do |t| create_table :ci_build_trace_chunks, id: :bigserial do |t|
t.integer :job_id, null: false t.integer :build_id, null: false
t.integer :chunk_index, null: false t.integer :chunk_index, null: false
t.integer :data_store, null: false t.integer :data_store, null: false
t.binary :raw_data t.binary :raw_data
t.foreign_key :ci_builds, column: :job_id, on_delete: :cascade t.foreign_key :ci_builds, column: :build_id, on_delete: :cascade
t.index [:job_id, :chunk_index], unique: true t.index [:build_id, :chunk_index], unique: true
end end
end end
end end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html # See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab. # for more information on how to write migrations for GitLab.
require Rails.root.join('db/migrate/limits_ci_job_trace_chunks_raw_data_for_mysql') require Rails.root.join('db/migrate/limits_ci_build_trace_chunks_raw_data_for_mysql')
class AddLimitsCiJobTraceChunksRawDataForMysql < ActiveRecord::Migration class AddLimitsCiBuildTraceChunksRawDataForMysql < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
def up def up
LimitsCiJobTraceChunksRawDataForMysql.new.up LimitsCiBuildTraceChunksRawDataForMysql.new.up
end end
end end
class LimitsCiJobTraceChunksRawDataForMysql < ActiveRecord::Migration class LimitsCiBuildTraceChunksRawDataForMysql < ActiveRecord::Migration
def up def up
return unless Gitlab::Database.mysql? return unless Gitlab::Database.mysql?
# Mysql needs MEDIUMTEXT type (up to 16MB) rather than TEXT (up to 64KB) # Mysql needs MEDIUMTEXT type (up to 16MB) rather than TEXT (up to 64KB)
# Because 'raw_data' is always capped by Ci::JobTraceChunk::CHUNK_SIZE, which is 128KB # Because 'raw_data' is always capped by Ci::BuildTraceChunk::CHUNK_SIZE, which is 128KB
change_column :ci_job_trace_chunks, :raw_data, :binary, limit: 16.megabytes - 1 #MEDIUMTEXT change_column :ci_build_trace_chunks, :raw_data, :binary, limit: 16.megabytes - 1 #MEDIUMTEXT
end end
end end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180425131009) do ActiveRecord::Schema.define(version: 20180425205249) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -246,6 +246,15 @@ ActiveRecord::Schema.define(version: 20180425131009) do ...@@ -246,6 +246,15 @@ ActiveRecord::Schema.define(version: 20180425131009) do
add_index "chat_teams", ["namespace_id"], name: "index_chat_teams_on_namespace_id", unique: true, using: :btree add_index "chat_teams", ["namespace_id"], name: "index_chat_teams_on_namespace_id", unique: true, using: :btree
create_table "ci_build_trace_chunks", id: :bigserial, force: :cascade do |t|
t.integer "build_id", null: false
t.integer "chunk_index", null: false
t.integer "data_store", null: false
t.binary "raw_data"
end
add_index "ci_build_trace_chunks", ["build_id", "chunk_index"], name: "index_ci_build_trace_chunks_on_build_id_and_chunk_index", unique: true, using: :btree
create_table "ci_build_trace_section_names", force: :cascade do |t| create_table "ci_build_trace_section_names", force: :cascade do |t|
t.integer "project_id", null: false t.integer "project_id", null: false
t.string "name", null: false t.string "name", null: false
...@@ -371,15 +380,6 @@ ActiveRecord::Schema.define(version: 20180425131009) do ...@@ -371,15 +380,6 @@ ActiveRecord::Schema.define(version: 20180425131009) do
add_index "ci_job_artifacts", ["job_id", "file_type"], name: "index_ci_job_artifacts_on_job_id_and_file_type", unique: true, using: :btree add_index "ci_job_artifacts", ["job_id", "file_type"], name: "index_ci_job_artifacts_on_job_id_and_file_type", unique: true, using: :btree
add_index "ci_job_artifacts", ["project_id"], name: "index_ci_job_artifacts_on_project_id", using: :btree add_index "ci_job_artifacts", ["project_id"], name: "index_ci_job_artifacts_on_project_id", using: :btree
create_table "ci_job_trace_chunks", id: :bigserial, force: :cascade do |t|
t.integer "job_id", null: false
t.integer "chunk_index", null: false
t.integer "data_store", null: false
t.binary "raw_data"
end
add_index "ci_job_trace_chunks", ["job_id", "chunk_index"], name: "index_ci_job_trace_chunks_on_job_id_and_chunk_index", unique: true, using: :btree
create_table "ci_pipeline_schedule_variables", force: :cascade do |t| create_table "ci_pipeline_schedule_variables", force: :cascade do |t|
t.string "key", null: false t.string "key", null: false
t.text "value" t.text "value"
...@@ -2075,6 +2075,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do ...@@ -2075,6 +2075,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do
add_foreign_key "boards", "namespaces", column: "group_id", on_delete: :cascade add_foreign_key "boards", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "boards", "projects", name: "fk_f15266b5f9", on_delete: :cascade add_foreign_key "boards", "projects", name: "fk_f15266b5f9", on_delete: :cascade
add_foreign_key "chat_teams", "namespaces", on_delete: :cascade add_foreign_key "chat_teams", "namespaces", on_delete: :cascade
add_foreign_key "ci_build_trace_chunks", "ci_builds", column: "build_id", on_delete: :cascade
add_foreign_key "ci_build_trace_section_names", "projects", on_delete: :cascade add_foreign_key "ci_build_trace_section_names", "projects", on_delete: :cascade
add_foreign_key "ci_build_trace_sections", "ci_build_trace_section_names", column: "section_name_id", name: "fk_264e112c66", on_delete: :cascade add_foreign_key "ci_build_trace_sections", "ci_build_trace_section_names", column: "section_name_id", name: "fk_264e112c66", on_delete: :cascade
add_foreign_key "ci_build_trace_sections", "ci_builds", column: "build_id", name: "fk_4ebe41f502", on_delete: :cascade add_foreign_key "ci_build_trace_sections", "ci_builds", column: "build_id", name: "fk_4ebe41f502", on_delete: :cascade
...@@ -2087,7 +2088,6 @@ ActiveRecord::Schema.define(version: 20180425131009) do ...@@ -2087,7 +2088,6 @@ ActiveRecord::Schema.define(version: 20180425131009) do
add_foreign_key "ci_group_variables", "namespaces", column: "group_id", name: "fk_33ae4d58d8", on_delete: :cascade add_foreign_key "ci_group_variables", "namespaces", column: "group_id", name: "fk_33ae4d58d8", on_delete: :cascade
add_foreign_key "ci_job_artifacts", "ci_builds", column: "job_id", on_delete: :cascade add_foreign_key "ci_job_artifacts", "ci_builds", column: "job_id", on_delete: :cascade
add_foreign_key "ci_job_artifacts", "projects", on_delete: :cascade add_foreign_key "ci_job_artifacts", "projects", on_delete: :cascade
add_foreign_key "ci_job_trace_chunks", "ci_builds", column: "job_id", on_delete: :cascade
add_foreign_key "ci_pipeline_schedule_variables", "ci_pipeline_schedules", column: "pipeline_schedule_id", name: "fk_41c35fda51", on_delete: :cascade add_foreign_key "ci_pipeline_schedule_variables", "ci_pipeline_schedules", column: "pipeline_schedule_id", name: "fk_41c35fda51", on_delete: :cascade
add_foreign_key "ci_pipeline_schedules", "projects", name: "fk_8ead60fcc4", on_delete: :cascade add_foreign_key "ci_pipeline_schedules", "projects", name: "fk_8ead60fcc4", on_delete: :cascade
add_foreign_key "ci_pipeline_schedules", "users", column: "owner_id", name: "fk_9ea99f58d2", on_delete: :nullify add_foreign_key "ci_pipeline_schedules", "users", column: "owner_id", name: "fk_9ea99f58d2", on_delete: :nullify
......
...@@ -54,14 +54,14 @@ module Gitlab ...@@ -54,14 +54,14 @@ module Gitlab
end end
def exist? def exist?
trace_artifact&.exists? || job.chunks.any? || current_path.present? || old_trace.present? trace_artifact&.exists? || job.trace_chunks.any? || current_path.present? || old_trace.present?
end end
def read def read
stream = Gitlab::Ci::Trace::Stream.new do stream = Gitlab::Ci::Trace::Stream.new do
if trace_artifact if trace_artifact
trace_artifact.open trace_artifact.open
elsif job.chunks.any? elsif job.trace_chunks.any?
Gitlab::Ci::Trace::ChunkedIO.new(job) Gitlab::Ci::Trace::ChunkedIO.new(job)
elsif current_path elsif current_path
File.open(current_path, "rb") File.open(current_path, "rb")
...@@ -100,7 +100,7 @@ module Gitlab ...@@ -100,7 +100,7 @@ module Gitlab
FileUtils.rm(trace_path, force: true) FileUtils.rm(trace_path, force: true)
end end
job.chunks.destroy_all job.trace_chunks.destroy_all
job.erase_old_trace! job.erase_old_trace!
end end
...@@ -108,7 +108,7 @@ module Gitlab ...@@ -108,7 +108,7 @@ module Gitlab
raise ArchiveError, 'Already archived' if trace_artifact raise ArchiveError, 'Already archived' if trace_artifact
raise ArchiveError, 'Job is not finished yet' unless job.complete? raise ArchiveError, 'Job is not finished yet' unless job.complete?
if job.chunks.any? if job.trace_chunks.any?
Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream| Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream|
archive_stream!(stream) archive_stream!(stream)
stream.destroy! stream.destroy!
...@@ -130,7 +130,7 @@ module Gitlab ...@@ -130,7 +130,7 @@ module Gitlab
def archive_stream!(stream) def archive_stream!(stream)
clone_file!(stream, JobArtifactUploader.workhorse_upload_path) do |clone_path| clone_file!(stream, JobArtifactUploader.workhorse_upload_path) do |clone_path|
create_job_trace!(job, clone_path) create_build_trace!(job, clone_path)
end end
end end
...@@ -146,7 +146,7 @@ module Gitlab ...@@ -146,7 +146,7 @@ module Gitlab
end end
end end
def create_job_trace!(job, path) def create_build_trace!(job, path)
File.open(path) do |stream| File.open(path) do |stream|
job.create_job_artifacts_trace!( job.create_job_artifacts_trace!(
project: job.project, project: job.project,
......
...@@ -5,18 +5,18 @@ module Gitlab ...@@ -5,18 +5,18 @@ module Gitlab
module Ci module Ci
class Trace class Trace
class ChunkedIO class ChunkedIO
CHUNK_SIZE = ::Ci::JobTraceChunk::CHUNK_SIZE CHUNK_SIZE = ::Ci::BuildTraceChunk::CHUNK_SIZE
FailedToGetChunkError = Class.new(StandardError) FailedToGetChunkError = Class.new(StandardError)
attr_reader :job attr_reader :build
attr_reader :tell, :size attr_reader :tell, :size
attr_reader :chunk, :chunk_range attr_reader :chunk, :chunk_range
alias_method :pos, :tell alias_method :pos, :tell
def initialize(job, &block) def initialize(build, &block)
@job = job @build = build
@chunks_cache = [] @chunks_cache = []
@tell = 0 @tell = 0
@size = calculate_size @size = calculate_size
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
@size = offset @size = offset
# remove all next chunks # remove all next chunks
job_chunks.where('chunk_index > ?', chunk_index).destroy_all trace_chunks.where('chunk_index > ?', chunk_index).destroy_all
# truncate current chunk # truncate current chunk
current_chunk.truncate(chunk_offset) if chunk_offset != 0 current_chunk.truncate(chunk_offset) if chunk_offset != 0
...@@ -157,7 +157,7 @@ module Gitlab ...@@ -157,7 +157,7 @@ module Gitlab
end end
def destroy! def destroy!
job_chunks.destroy_all trace_chunks.destroy_all
@tell = @size = 0 @tell = @size = 0
ensure ensure
invalidate_chunk_cache invalidate_chunk_cache
...@@ -206,23 +206,23 @@ module Gitlab ...@@ -206,23 +206,23 @@ module Gitlab
end end
def current_chunk def current_chunk
@chunks_cache[chunk_index] ||= job_chunks.find_by(chunk_index: chunk_index) @chunks_cache[chunk_index] ||= trace_chunks.find_by(chunk_index: chunk_index)
end end
def build_chunk def build_chunk
@chunks_cache[chunk_index] = ::Ci::JobTraceChunk.new(job: job, chunk_index: chunk_index) @chunks_cache[chunk_index] = ::Ci::BuildTraceChunk.new(build: build, chunk_index: chunk_index)
end end
def ensure_chunk def ensure_chunk
current_chunk || build_chunk current_chunk || build_chunk
end end
def job_chunks def trace_chunks
::Ci::JobTraceChunk.where(job: job) ::Ci::BuildTraceChunk.where(build: build)
end end
def calculate_size def calculate_size
job_chunks.order(chunk_index: :desc).first.try(&:end_offset).to_i trace_chunks.order(chunk_index: :desc).first.try(&:end_offset).to_i
end end
end end
end end
......
require Rails.root.join('db/migrate/limits_to_mysql') require Rails.root.join('db/migrate/limits_to_mysql')
require Rails.root.join('db/migrate/markdown_cache_limits_to_mysql') require Rails.root.join('db/migrate/markdown_cache_limits_to_mysql')
require Rails.root.join('db/migrate/merge_request_diff_file_limits_to_mysql') require Rails.root.join('db/migrate/merge_request_diff_file_limits_to_mysql')
require Rails.root.join('db/migrate/limits_ci_job_trace_chunks_raw_data_for_mysql') require Rails.root.join('db/migrate/limits_ci_build_trace_chunks_raw_data_for_mysql')
desc "GitLab | Add limits to strings in mysql database" desc "GitLab | Add limits to strings in mysql database"
task add_limits_mysql: :environment do task add_limits_mysql: :environment do
...@@ -9,5 +9,5 @@ task add_limits_mysql: :environment do ...@@ -9,5 +9,5 @@ task add_limits_mysql: :environment do
LimitsToMysql.new.up LimitsToMysql.new.up
MarkdownCacheLimitsToMysql.new.up MarkdownCacheLimitsToMysql.new.up
MergeRequestDiffFileLimitsToMysql.new.up MergeRequestDiffFileLimitsToMysql.new.up
LimitsCiJobTraceChunksRawDataForMysql.new.up LimitsCiBuildTraceChunksRawDataForMysql.new.up
end end
FactoryBot.define do FactoryBot.define do
factory :ci_job_trace_chunk, class: Ci::JobTraceChunk do factory :ci_build_trace_chunk, class: Ci::BuildTraceChunk do
job factory: :ci_build job factory: :ci_build
chunk_index 0 chunk_index 0
data_store :redis data_store :redis
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
include ChunkedIOHelpers include ChunkedIOHelpers
set(:job) { create(:ci_build, :running) } set(:build) { create(:ci_build, :running) }
let(:chunked_io) { described_class.new(job) } let(:chunked_io) { described_class.new(build) }
before do before do
stub_feature_flags(ci_enable_live_trace: true) stub_feature_flags(ci_enable_live_trace: true)
...@@ -13,7 +13,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -13,7 +13,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context "#initialize" do context "#initialize" do
context 'when a chunk exists' do context 'when a chunk exists' do
before do before do
job.trace.set('ABC') build.trace.set('ABC')
end end
it { expect(chunked_io.size).to eq(3) } it { expect(chunked_io.size).to eq(3) }
...@@ -22,7 +22,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -22,7 +22,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when two chunks exist' do context 'when two chunks exist' do
before do before do
stub_buffer_size(4) stub_buffer_size(4)
job.trace.set('ABCDEF') build.trace.set('ABCDEF')
end end
it { expect(chunked_io.size).to eq(6) } it { expect(chunked_io.size).to eq(6) }
...@@ -37,7 +37,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -37,7 +37,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
subject { chunked_io.seek(pos, where) } subject { chunked_io.seek(pos, where) }
before do before do
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
context 'when moves pos to end of the file' do context 'when moves pos to end of the file' do
...@@ -68,7 +68,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -68,7 +68,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
subject { chunked_io.eof? } subject { chunked_io.eof? }
before do before do
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
context 'when current pos is at end of the file' do context 'when current pos is at end of the file' do
...@@ -94,7 +94,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -94,7 +94,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'yields lines' do it 'yields lines' do
...@@ -106,7 +106,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -106,7 +106,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'calls get_chunk only once' do it 'calls get_chunk only once' do
...@@ -127,7 +127,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -127,7 +127,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it { is_expected.to eq(sample_trace_raw) } it { is_expected.to eq(sample_trace_raw) }
...@@ -136,7 +136,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -136,7 +136,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it { is_expected.to eq(sample_trace_raw) } it { is_expected.to eq(sample_trace_raw) }
...@@ -149,7 +149,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -149,7 +149,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -160,7 +160,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -160,7 +160,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -175,7 +175,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -175,7 +175,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -186,7 +186,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -186,7 +186,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -201,7 +201,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -201,7 +201,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -212,7 +212,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -212,7 +212,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it 'reads a trace' do it 'reads a trace' do
...@@ -238,7 +238,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -238,7 +238,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it_behaves_like 'all line matching' it_behaves_like 'all line matching'
...@@ -247,7 +247,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -247,7 +247,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
end end
it_behaves_like 'all line matching' it_behaves_like 'all line matching'
...@@ -256,7 +256,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -256,7 +256,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when pos is at middle of the file' do context 'when pos is at middle of the file' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(sample_trace_raw) build.trace.set(sample_trace_raw)
chunked_io.seek(chunked_io.size / 2) chunked_io.seek(chunked_io.size / 2)
string_io.seek(string_io.size / 2) string_io.seek(string_io.size / 2)
...@@ -316,7 +316,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -316,7 +316,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2) stub_buffer_size(sample_trace_raw.bytesize / 2)
job.trace.set(exist_data) build.trace.set(exist_data)
end end
it_behaves_like 'appends a trace' it_behaves_like 'appends a trace'
...@@ -325,7 +325,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -325,7 +325,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is larger than file size' do context 'when buffer size is larger than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize * 2) stub_buffer_size(sample_trace_raw.bytesize * 2)
job.trace.set(exist_data) build.trace.set(exist_data)
end end
it_behaves_like 'appends a trace' it_behaves_like 'appends a trace'
...@@ -349,7 +349,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do ...@@ -349,7 +349,7 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
context 'when buffer size is smaller than file size' do context 'when buffer size is smaller than file size' do
before do before do
stub_buffer_size(sample_trace_raw.bytesize / 2)