Repository: rails/rails
File: activesupport/lib/active_support/test_case.rb (Ruby)

Code before:
require "active_support/testing/time_helpers"
require "active_support/testing/constant_stubbing"
require "active_support/testing/file_fixtures"
require "active_support/testing/parallelization"
require "active_support/testing/parallelize_executor"
require "active_support/testing/notification_assertions"
require "concurrent/utility/processor_counter"

module ActiveSupport
  class TestCase < ::Minitest::Test
    Assertion = Minitest::Assertion
    
    # Class variable to store the parallel worker ID
    @@parallel_worker_id = nil

    class << self
      # Returns the current parallel worker ID if tests are running in parallel,
      # nil otherwise.
      #
      #   ActiveSupport::TestCase.parallel_worker_id # => 2
      def parallel_worker_id
        @@parallel_worker_id
      end
      
      # Sets the parallel worker ID
      def parallel_worker_id=(value)
        @@parallel_worker_id = value
      end

      # Sets the order in which test cases are run.
      #
      #   ActiveSupport::TestCase.test_order = :random # => :random
      #
      # Valid values are:
      # * +:random+   (to run tests in random order)
      # * +:parallel+ (to run tests in parallel)
      # * +:sorted+   (to run tests alphabetically by method name)
      # * +:alpha+    (equivalent to +:sorted+)
      def test_order=(new_order)
        ActiveSupport.test_order = new_order
      end

      # Returns the order in which test cases are run.
      #
      #   ActiveSupport::TestCase.test_order # => :random
      #
      # Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+.
      # Defaults to +:random+.
      def test_order
        ActiveSupport.test_order ||= :random
      end

Review comment (bug):
I'm not sure we want this API to be public (just the setter) because if someone sets this in their application weird things will happen and they'll think it's a bug in Rails. Only the framework should set this value. So this should have a `# :nodoc` instead of docs.

```suggestion
      def parallel_worker_id=(value) # :nodoc:
```

Code after:
require "active_support/testing/time_helpers"
require "active_support/testing/constant_stubbing"
require "active_support/testing/file_fixtures"
require "active_support/testing/parallelization"
require "active_support/testing/parallelize_executor"
require "active_support/testing/notification_assertions"
require "concurrent/utility/processor_counter"

module ActiveSupport
  class TestCase < ::Minitest::Test
    Assertion = Minitest::Assertion

    # Class variable to store the parallel worker ID
    @@parallel_worker_id = nil

    class << self
      # Returns the current parallel worker ID if tests are running in parallel,
      # nil otherwise.
      #
      #   ActiveSupport::TestCase.parallel_worker_id # => 2
      def parallel_worker_id
        @@parallel_worker_id
      end

      def parallel_worker_id=(value) # :nodoc:
        @@parallel_worker_id = value
      end

      # Sets the order in which test cases are run.
      #
      #   ActiveSupport::TestCase.test_order = :random # => :random
      #
      # Valid values are:
      # * +:random+   (to run tests in random order)
      # * +:parallel+ (to run tests in parallel)
      # * +:sorted+   (to run tests alphabetically by method name)
      # * +:alpha+    (equivalent to +:sorted+)
      def test_order=(new_order)
        ActiveSupport.test_order = new_order
      end

      # Returns the order in which test cases are run.
      #
      #   ActiveSupport::TestCase.test_order # => :random
      #
      # Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+.
      # Defaults to +:random+.
      def test_order
        ActiveSupport.test_order ||= :random
      end