logstash/qa
github-actions[bot] ff37802a77
Unicode pipeline and plugin ids (#15971) (#16257)
* fix: restore support for unicode pipeline- and plugin-id's

JRuby's `Ruby#newSymbol(String)` throws an exception when provided a `String`
that contains characters outside of lower-ASCII because JRuby internals expect
"the incoming String to be one of our mangled ISO-8859-1 strings" as noted in
a comment on jruby/jruby#6217.

Instead, we use `Ruby#newString(String)` to create a new `RubyString` (which
works properly), and then rely on `RubyString#intern` to get our `RubySymbol`.

This fixes a regression introduced in the 8.7 series in which pipeline id's
are consistently represented as ruby symbols in the metrics store, and ensures
similar issue does not exist when specifying a plugin id that contains
characters above the lower-ASCII plane.

* fix: use properly-encoded RubySymbol in PipelineConfig

We cannot rely on `RubySymbol#toString` to produce a properly-encoded `String`
whe the string contains characters above the lower-ASCII plane because the
result is effectively a binary ruby-internal marshal of the bytes that only
holds when the symbol contains lower-ASCII.

Instead, we can use the internally-memoizing `RubySymbol#name` to get a
properly-encoded `RubyString`, and `RubyString#asJavaString()` to get a
properly-encoded java-`String`.

* fix: properly serialize unicode pipeline names in API output

Jackson's JSON serializer leaks the JRuby-internal byte structure of Symbols,
which only aligns with the byte-structure of the symbol's actual string when
that string is wholly-comprised of lower-ASCII characters.

By pre-converting Symbols to Strings, we ensure that the result is readable
and useful.

* spec: bypass monitoring specs for unicode pipeline ids when PQ enabled

(cherry picked from commit 0ec16ca398)

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
2024-06-25 09:46:55 -07:00
..
acceptance Follow up to #15900 -- fix remaining acceptance tests (#15907) 2024-02-15 11:33:17 +02:00
docker Fix integration tests caused by #16026. (#16038) 2024-03-28 09:08:00 -07:00
integration Unicode pipeline and plugin ids (#15971) (#16257) 2024-06-25 09:46:55 -07:00
rspec Fix packaging service check failures (#15946) 2024-02-15 10:01:47 +02:00
scripts/windows Spelling fixes (#6806) 2017-03-29 19:33:26 -07:00
support/logstash-filter-qatest Rubocop: Enable SpaceAround cops (#15196) 2023-07-18 21:11:57 -04:00
.gitignore relocate windows scripted tests into the qa folder 2016-05-12 06:56:25 +00:00
.rspec add .rspec file to the qa dir so the default formater is documentation 2016-06-29 04:47:15 -04:00
Gemfile Refactor qa/acceptance tests to get away from vagrant (#15696) 2024-01-08 09:40:58 +02:00
Rakefile Refactor qa/acceptance tests to get away from vagrant (#15696) 2024-01-08 09:40:58 +02:00
README.md Refactor qa/acceptance tests to get away from vagrant (#15696) 2024-01-08 09:40:58 +02:00

Acceptance test Framework

The acceptance test framework for Logstash is intended to test the functionality of packages (.deb, .rpm) on various supported platforms.

In this small README we describe its features and the steps necessary for executing it and adding new tests.

Description

In summary this test framework is composed of:

  • A collection of rspec helpers and matchers that make creating tests easy.
  • Rspecs helpers that execute commands.

The tests are expected to be executed on the target environment e.g. an Ubuntu 22.04 vm.

Running tests/Prerequisites

To run the tests from a fresh Logstash checkout, you need to:

  1. ./gradlew clean boostrap 2a. Build the necessary package artifacts e.g. rake artifact:deb OR 2b. Supply a directory where pregenerated package artifacts exit via the LS_ARTIFACTS_PATH environment variable (relative and absolute paths are supported).
  2. cd qa
  3. bundle install

Now you are ready to kick off the tests:

  1. rake qa:acceptance:all.

Steps 1, 2b, 3, 4, 5 are executed by the ci/acceptance_tests.sh script.

Architecture of the Framework

Directory structure

  • acceptance/: all the specs definitions.
  • rspec: all framework parts necessary to get the test running. Includes the commands, the rspec matchers and a collection of useful helpers.

I want to add a test, what should I do?

To add a test you basically should start by the acceptance directory, here you will find an already created tests, most important locations here are:

  • lib here is where the tests are living. If a test is not going to be reused it should be created here.
  • shared_examples inside that directory should be living all tests that could be reused in different scenarios, like you can see the CLI ones.

but we want to write tests, here is an example of how do they look like, including the different moving parts we encounter in the framework.

    logstash = ServiceTester::Artifact.new()

    ## your test code goes here.

    # example:
    it_behaves_like "installable_with_jdk", logstash
    it_behaves_like "updated", logstash, from_release_branch="7.17"

Inside the rspec directory you will find a collection of commands, organized per operating system, which will let you operate and get your tests done.

You'll probably find enough supporting classes for different platforms, but if not, feel free to add more.

An example of an install command on debian looks like:

    def installed?(package)
      stdout = ""
      cmd = sudo_exec!("dpkg -s #{package}")
      stdout = cmd.stdout
      stdout.match(/^Package: #{package}$/)
      stdout.match(/^Status: install ok installed$/)
    end
  end

this is how we run operations and wrap them as ruby code.

Running a test (detailed level)

There is also the possibility to run your tests with more granularity by using the rspec command, this will let you for example run a single tests, a collection of them using filtering, etc.

Check https://relishapp.com/rspec/rspec-core/v/3-4/docs/command-line for more details, but here is a quick cheat sheet to run them:

Run the examples that get "is installed" in their description

  • bundle exec rspec acceptance/spec -e "is installed"

Run the example defined at line 11

  • bundle exec rspec acceptance/spec/lib/artifact_operation_spec.rb:11