Class: TestRunner::TestResources

Inherits:
Object
  • Object
show all
Defined in:
lib/test-runner/test_resources.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machines: 0, memory_mib: 0, shm_mib: memory_mib, max_machine_memory_mib: 0, cpus: 0) ⇒ TestResources

Returns a new instance of TestResources.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/test-runner/test_resources.rb', line 35

def initialize(
  machines: 0,
  memory_mib: 0,
  shm_mib: memory_mib,
  max_machine_memory_mib: 0,
  cpus: 0
)
  @machines = machines
  @memory_mib = memory_mib
  @shm_mib = shm_mib
  @max_machine_memory_mib = max_machine_memory_mib
  @cpus = cpus
end

Instance Attribute Details

#cpusInteger (readonly)

Returns:

  • (Integer)


16
17
18
# File 'lib/test-runner/test_resources.rb', line 16

def cpus
  @cpus
end

#machinesInteger (readonly)

Returns:

  • (Integer)


4
5
6
# File 'lib/test-runner/test_resources.rb', line 4

def machines
  @machines
end

#max_machine_memory_mibInteger (readonly)

Returns:

  • (Integer)


13
14
15
# File 'lib/test-runner/test_resources.rb', line 13

def max_machine_memory_mib
  @max_machine_memory_mib
end

#memory_mibInteger (readonly)

Returns:

  • (Integer)


7
8
9
# File 'lib/test-runner/test_resources.rb', line 7

def memory_mib
  @memory_mib
end

#shm_mibInteger (readonly)

Returns:

  • (Integer)


10
11
12
# File 'lib/test-runner/test_resources.rb', line 10

def shm_mib
  @shm_mib
end

Class Method Details

.from_h(data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/test-runner/test_resources.rb', line 18

def self.from_h(data)
  data ||= {}

  memory_mib = data.fetch('memoryMiB', data.fetch(:memory_mib, 0)).to_i

  new(
    machines: data.fetch('machines', 0).to_i,
    memory_mib:,
    shm_mib: data.fetch('shmMiB', data.fetch(:shm_mib, memory_mib)).to_i,
    max_machine_memory_mib: data.fetch(
      'maxMachineMemoryMiB',
      data.fetch(:max_machine_memory_mib, 0)
    ).to_i,
    cpus: data.fetch('cpus', 0).to_i
  )
end

Instance Method Details

#+(other) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/test-runner/test_resources.rb', line 49

def +(other)
  self.class.new(
    machines: machines + other.machines,
    memory_mib: memory_mib + other.memory_mib,
    shm_mib: shm_mib + other.shm_mib,
    max_machine_memory_mib: [max_machine_memory_mib, other.max_machine_memory_mib].max,
    cpus: cpus + other.cpus
  )
end

#-(other) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/test-runner/test_resources.rb', line 59

def -(other)
  self.class.new(
    machines: machines - other.machines,
    memory_mib: memory_mib - other.memory_mib,
    shm_mib: shm_mib - other.shm_mib,
    max_machine_memory_mib: max_machine_memory_mib,
    cpus: cpus - other.cpus
  )
end

#format_mib(value) ⇒ Object (protected)



80
81
82
83
84
# File 'lib/test-runner/test_resources.rb', line 80

def format_mib(value)
  return "#{value} MiB" if value < 1024

  format('%.1f GiB', value / 1024.0)
end

#summaryObject



73
74
75
76
# File 'lib/test-runner/test_resources.rb', line 73

def summary
  "machines=#{machines}, memory=#{format_mib(memory_mib)}, " \
    "shm=#{format_mib(shm_mib)}, cpus=#{cpus}"
end

#zero?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/test-runner/test_resources.rb', line 69

def zero?
  machines <= 0 && memory_mib <= 0 && shm_mib <= 0 && cpus <= 0
end