Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-4976

Older Windows modules contain rspec configuration which blocks junit test files

    XMLWordPrintable

    Details

    • Type: CI Blocker
    • Status: Resolved
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • QA Risk Assessment:
      Needs Assessment

      Description

      I noticed that the PowerShell module (and then the ACL) module kept reporting that the spec tests were completing but were unstable in Jenkins. Even after I tested this on the registry module ok.

      After a lot of debugging I found this in spec_helper.rb in PowerShell:

        if Puppet::Util::Platform.windows?
          config.output_stream = $stdout
          config.error_stream = $stderr
          config.formatters.each { |f| f.instance_variable_set(:@output, $stdout) }
        end
      

      This would redirect all test output to STDOUT which would explain why I kept seeing bulk XML in Jenkins, BUT the testresult.xml file was empty.

      In the registry module I found this in spec_helper.rb:

        if File::ALT_SEPARATOR && RUBY_VERSION =~ /^1\./
          require 'win32console'
          c.output_stream = $stdout
          c.error_stream = $stderr
          c.formatters.each { |f| f.instance_variable_set(:@output, $stdout) }
        end
      

      At some point we guarded this behaviour to only happen on Ruby 1.x which is why it had no effect on Ruby 2.x

      After digging around in the Puppet codebase I found this:
      https://github.com/puppetlabs/puppet/commit/4ffc02d22093f0b76046a51eee603932a9b14f62

      +  if Puppet::Util::Platform.windows?
       +    config.output_stream = $stdout
       +    config.error_stream = $stderr
       +    config.formatters.each { |f| f.instance_variable_set(:@output, $stdout) }
       +  end
      ----
      Commit `83cfe9d` added colorized rspec output by default. Unfortunately,
      this doesn't work on Windows and causes ANSI escape characters to be
      printed to stdout.
       
      Although we load the `win32console` gem while requiring puppet, rspec
      always writes to `$stdout` and `$stderr` that it was started with. So
      later when the `win32console` gem overwrites those streams, the formatters
      have already been created with the old ones.
       
      This commit modifies the spec helper to reset the stdout and stderr
      streams on the configuration object, as well as each of the formatters.
      Unfortunately, the formatter does not expose an accessor for its output
      variable. I tested with 2.9 and 2.11, and both work as expected, i.e.
      color on Windows.
       
      This commit doesn't change behavior on non-Windows platforms.
      

      However junit is working in the Puppet pipelines. I found a later commit which fixed this:
      https://github.com/puppetlabs/puppet/commit/0babce626adb2e59bf212e4272b9e088a7b559a7

      +    config.formatters.each do |f|
       +      if not f.instance_variable_get(:@output).kind_of?(::File)
       +        f.instance_variable_set(:@output, $stdout)
       +      end
       +    end
      ---
      (Maint) Do not overwrite file output
      The windows spec code resets the output streams so that it can handle
      color correctly. In doing so it assumed that everything was writing to
      stdout, which is not the case when -o is used on the command line.
      

      So it seems this logic was put in because of the win32_console gem. After auditing a bunch of windows modules I found that the older modules had this code, while newer ones (wsus_client, chocolatey) did not and still tested correctly.

      However as Puppet 3.x is now well and truly end of life, we can remove this behaviour entirely.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              glenn.sarti Glenn Sarti
              Reporter:
              glenn.sarti Glenn Sarti
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support