Commit 409a16ba authored by Andy Soiron's avatar Andy Soiron Committed by Kamil Trzciński

Use Unix Time for Jira update sequence id

Monotonic Time counts the number of seconds since
system boot. This means it resets with every deploy
and can be different in each processes. Unix Time
counts the number of seconds since 1970-1-1 UTC.
parent ddad0826
---
title: Change Jira Connect update sequence id to use Unix Time
merge_request: 51697
author:
type: fixed
...@@ -4,7 +4,7 @@ module Atlassian ...@@ -4,7 +4,7 @@ module Atlassian
module JiraConnect module JiraConnect
class Client < Gitlab::HTTP class Client < Gitlab::HTTP
def self.generate_update_sequence_id def self.generate_update_sequence_id
Gitlab::Metrics::System.monotonic_time.to_i (Time.now.utc.to_f * 1000).round
end end
def initialize(base_uri, shared_secret) def initialize(base_uri, shared_secret)
......
...@@ -18,15 +18,15 @@ RSpec.describe Atlassian::JiraConnect::Client do ...@@ -18,15 +18,15 @@ RSpec.describe Atlassian::JiraConnect::Client do
end end
end end
around do |example|
freeze_time { example.run }
end
describe '.generate_update_sequence_id' do describe '.generate_update_sequence_id' do
it 'returns monotonic_time converted it to integer' do it 'returns unix time in microseconds as integer', :aggregate_failures do
allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(1.0) travel_to(Time.utc(1970, 1, 1, 0, 0, 1)) do
expect(described_class.generate_update_sequence_id).to eq(1000)
end
expect(described_class.generate_update_sequence_id).to eq(1) travel_to(Time.utc(1970, 1, 1, 0, 0, 5)) do
expect(described_class.generate_update_sequence_id).to eq(5000)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment