Class: CI::Queue::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/queue/static.rb

Direct Known Subclasses

File, Redis::Retry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tests, config) ⇒ Static

Returns a new instance of Static.



13
14
15
16
17
18
# File 'lib/ci/queue/static.rb', line 13

def initialize(tests, config)
  @queue = tests
  @config = config
  @progress = 0
  @total = tests.size
end

Instance Attribute Details

#progress ⇒ Object (readonly)

Returns the value of attribute progress.



11
12
13
# File 'lib/ci/queue/static.rb', line 11

def progress
  @progress
end

#total ⇒ Object (readonly)

Returns the value of attribute total.



11
12
13
# File 'lib/ci/queue/static.rb', line 11

def total
  @total
end

Class Method Details

.from_uri(uri, config) ⇒ Object



5
6
7
8
# File 'lib/ci/queue/static.rb', line 5

def from_uri(uri, config)
  tests = uri.opaque.split(':').map { |t| CGI.unescape(t) }
  new(tests, config)
end

Instance Method Details

#acknowledge(test) ⇒ Object



63
64
65
# File 'lib/ci/queue/static.rb', line 63

def acknowledge(test)
  true
end

#exhausted? ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ci/queue/static.rb', line 59

def exhausted?
  @queue.empty?
end

#minitest_reporters ⇒ Object



20
21
22
23
24
25
# File 'lib/ci/queue/static.rb', line 20

def minitest_reporters
  require 'minitest/reporters/queue_reporter'
  @minitest_reporters ||= [
    Minitest::Reporters::QueueReporter.new,
  ]
end

#poll ⇒ Object



52
53
54
55
56
57
# File 'lib/ci/queue/static.rb', line 52

def poll
  while test = @queue.shift
    yield index.fetch(test)
    @progress += 1
  end
end

#populate(tests, random: nil) ⇒ Object



35
36
37
38
# File 'lib/ci/queue/static.rb', line 35

def populate(tests, random: nil)
  @index = tests.map { |t| [t.id, t] }.to_h
  self
end

#populated? ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ci/queue/static.rb', line 40

def populated?
  !!defined?(@index)
end

#requeue(test) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/ci/queue/static.rb', line 67

def requeue(test)
  test_key = test.id
  return false unless should_requeue?(test_key)
  requeues[test_key] += 1
  @queue.unshift(test_key)
  true
end

#retry_queue ⇒ Object



31
32
33
# File 'lib/ci/queue/static.rb', line 31

def retry_queue
  self
end

#size ⇒ Object



48
49
50
# File 'lib/ci/queue/static.rb', line 48

def size
  @queue.size
end

#supervisor ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/ci/queue/static.rb', line 27

def supervisor
  raise NotImplementedError, "This type of queue can't be supervised"
end

#to_a ⇒ Object



44
45
46
# File 'lib/ci/queue/static.rb', line 44

def to_a
  @queue.map { |i| index.fetch(i) }
end