Back to Repositories

Testing Debug Agent Input Plugin Configuration in Fluentd

This test suite validates the Debug Agent Input plugin functionality in Fluentd, focusing on Unix socket paths and multi-worker environment configurations. The tests ensure proper handling of socket paths and port assignments across different worker scenarios.

Test Coverage Overview

The test suite provides comprehensive coverage of the Debug Agent Input plugin’s core functionality:

  • Unix socket path validation and writability checks
  • Multi-worker environment port allocation
  • Unix path behavior in multi-worker setups
  • Error handling for invalid configurations

Implementation Analysis

The testing approach utilizes Fluent’s test driver framework to simulate plugin behavior and worker environments. The implementation employs systematic validation of configuration parameters and worker-specific adjustments for ports and Unix paths.

  • Test driver configuration validation
  • System config overwriting for worker testing
  • Instance variable manipulation for worker simulation

Technical Details

Testing infrastructure includes:

  • Fluent::Test::Driver::Input for plugin testing
  • FileUtils for temporary directory management
  • Test::Unit assertions for validation
  • SystemConfig overwrite capabilities for worker simulation

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test setup and cleanup with temporary directory management
  • Isolated test cases for specific functionality
  • Comprehensive error case validation
  • Clear separation of configuration and execution concerns

fluent/fluentd

test/plugin/test_in_debug_agent.rb

            
require_relative '../helper'
require 'fluent/test/driver/input'
require 'fluent/plugin/in_debug_agent'
require 'fileutils'

class DebugAgentInputTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
    FileUtils.rm_rf(TMP_DIR)
    FileUtils.mkdir_p(TMP_DIR)
  end

  TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/in_debug_agent")

  def create_driver(conf = '')
    Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput).configure(conf)
  end

  def test_unix_path_writable
    assert_nothing_raised do
      create_driver %[unix_path #{TMP_DIR}/test_path]
    end

    assert_raise(Fluent::ConfigError) do
      create_driver %[unix_path #{TMP_DIR}/does_not_exist/test_path]
    end
  end

  def test_multi_worker_environment_with_port
    Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
      d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
      d.instance.instance_eval { @_fluentd_worker_id = 2 }
      d.configure('port 24230')

      assert_true d.instance.multi_workers_ready?
      assert_equal(24232, d.instance.instance_variable_get(:@port))
    end
  end

  def test_multi_worker_environment_with_unix_path
    Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
      d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
      d.instance.instance_eval { @_fluentd_worker_id = 2 }
      d.configure("unix_path #{TMP_DIR}/test_path")

      assert_false d.instance.multi_workers_ready?
    end
  end
end