BigW Consortium Gitlab

sidekiq_helper_spec.rb 2.64 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe SidekiqHelper do
  describe 'parse_sidekiq_ps' do
    it 'parses line with time' do
      line = '55137	10,0	2,1	S+	2:30pm	sidekiq 4.1.4 gitlab [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)
Pascal Betz committed
8

9 10 11 12 13 14
      expect(parts).to eq(['55137', '10,0', '2,1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
    end

    it 'parses line with date' do
      line = '55137	10,0	2,1	S+	Aug 4	sidekiq 4.1.4 gitlab [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)
Pascal Betz committed
15

16 17 18 19 20 21
      expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 4', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
    end

    it 'parses line with two digit date' do
      line = '55137	10,0	2,1	S+	Aug 04	sidekiq 4.1.4 gitlab [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)
Pascal Betz committed
22

23 24 25 26 27 28
      expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 04', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
    end

    it 'parses line with dot as float separator' do
      line = '55137	10.0	2.1	S+	2:30pm	sidekiq 4.1.4 gitlab [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)
Pascal Betz committed
29

30 31 32
      expect(parts).to eq(['55137', '10.0', '2.1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]'])
    end

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    it 'parses OSX output' do
      line = ' 1641   1.5  3.8 S+    4:04PM sidekiq 4.2.1 gitlab [0 of 25 busy]'
      parts = helper.parse_sidekiq_ps(line)

      expect(parts).to eq(['1641', '1.5', '3.8', 'S+', '4:04PM', 'sidekiq 4.2.1 gitlab [0 of 25 busy]'])
    end

    it 'parses Ubuntu output' do
      # Ubuntu Linux 16.04 LTS / procps-3.3.10-4ubuntu2
      line = '  938  1.4  2.5 Sl+  21:23:21 sidekiq 4.2.1 gitlab [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)

      expect(parts).to eq(['938', '1.4', '2.5', 'Sl+', '21:23:21', 'sidekiq 4.2.1 gitlab [0 of 25 busy]'])
    end

    it 'parses Debian output' do
      # Debian Linux Wheezy/Jessie
      line = '17725  1.0 12.1 Ssl  19:20:15 sidekiq 4.2.1 gitlab-rails [0 of 25 busy]   '
      parts = helper.parse_sidekiq_ps(line)

      expect(parts).to eq(['17725', '1.0', '12.1', 'Ssl', '19:20:15', 'sidekiq 4.2.1 gitlab-rails [0 of 25 busy]'])
    end

56 57 58 59 60 61 62 63
    it 'parses OpenBSD output' do
      # OpenBSD 6.1
      line = '49258  0.5  2.3 R/0   Fri10PM  ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)'
      parts = helper.parse_sidekiq_ps(line)

      expect(parts).to eq(['49258', '0.5', '2.3', 'R/0', 'Fri10PM', 'ruby23: sidekiq 4.2.7 gitlab [0 of 25 busy] (ruby23)'])
    end

64 65 66
    it 'does fail gracefully on line not matching the format' do
      line = '55137	10.0	2.1	S+	2:30pm	something'
      parts = helper.parse_sidekiq_ps(line)
Pascal Betz committed
67

68 69 70 71
      expect(parts).to eq(['?', '?', '?', '?', '?', '?'])
    end
  end
end