Verified Commit ee62f3aa authored by Hercules Merscher's avatar Hercules Merscher 🌴
Browse files

fix: Undoing the start method changes

parent 016ad99c
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ module Labkit
      # Start the User Experience.
      #
      # @yield [self] When a block is provided, the experience will be completed automatically.
      # @param start_time [Time] An optional Time object to set the start time. Defaults to Time.now. UTC enforced.
      # @param extra [Hash] Additional data to include in the log event
      # @return [self]
      # @raise [UserExperienceError] If the block raises an error.
@@ -76,8 +75,8 @@ module Labkit
      #  experience.start
      #  experience.checkpoint
      #  experience.complete
      def start(start_time: Time.now.utc, **extra, &)
        @start_time = start_time.utc
      def start(**extra, &)
        @start_time = Time.now.utc
        checkpoint_counter.increment(checkpoint: "start", **base_labels)
        log_event("start", **extra)

+2 −17
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do
        user_experience_id: 'malicious_experience',
        feature_category: 'malicious_category',
        urgency: 'malicious_urgency',
        start_time: 'yesterday',
        elapsed_time_s: '999',
        urgency_threshold_s: '888'
      }
@@ -61,6 +62,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do
          user_experience_id: 'testing_sample',
          feature_category: 'source_code_management',
          urgency: 'sync_fast',
          start_time: be_a(String),
          elapsed_time_s: be_a(Numeric),
          urgency_threshold_s: 2,
        )
@@ -204,23 +206,6 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do

        expect(Labkit::UserExperienceSli::Current.active_experiences).to have_key(experience.id)
      end

      it 'uses provided start_time converted to UTC' do
        non_utc_start_time = Time.new(2024, 1, 1, 10, 30, 45, '+05:30')

        experience.start(start_time: non_utc_start_time)

        expect(experience.start_time).to eq(non_utc_start_time.utc)
      end

      it 'uses current UTC time when start_time is not provided' do
        now_utc = Time.new(2024, 1, 1, 0, 0, 0, '+00:00')
        allow(Time).to receive(:now).and_return(now_utc)

        experience.start

        expect(experience.start_time).to eq(now_utc)
      end
    end
  end