Class: Evilution::Runner::MutationExecutor::ResultCache

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/runner/mutation_executor/result_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ ResultCache

Returns a new instance of ResultCache.



12
13
14
# File 'lib/evilution/runner/mutation_executor/result_cache.rb', line 12

def initialize(backend)
  @backend = backend
end

Instance Method Details

#fetch(mutation) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/evilution/runner/mutation_executor/result_cache.rb', line 16

def fetch(mutation)
  return nil unless @backend

  data = @backend.fetch(mutation)
  return nil unless data
  return nil unless CACHEABLE_STATUSES.include?(data[:status])

  Evilution::Result::MutationResult.new(
    mutation: mutation,
    status: data[:status],
    duration: data[:duration],
    killing_test: data[:killing_test],
    test_command: data[:test_command]
  )
end

#partition(batch, packer:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/evilution/runner/mutation_executor/result_cache.rb', line 43

def partition(batch, packer:)
  uncached_indices = []
  cached_results = {}

  batch.each_with_index do |mutation, i|
    if mutation.unparseable?
      cached_results[i] = packer.compact(unparseable_result(mutation))
      next
    end

    cached = fetch(mutation)
    if cached
      cached_results[i] = packer.compact(cached)
    else
      uncached_indices << i
    end
  end

  [uncached_indices, cached_results]
end

#store(mutation, result) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/evilution/runner/mutation_executor/result_cache.rb', line 32

def store(mutation, result)
  return unless @backend
  return unless result.killed? || result.timeout?

  @backend.store(mutation,
                 status: result.status,
                 duration: result.duration,
                 killing_test: result.killing_test,
                 test_command: result.test_command)
end