|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | +Set-PSDebug -Trace 1 |
| 3 | + |
| 4 | +$default_conf_path = (Resolve-Path fluent.conf).Path |
| 5 | +$current_path = (Get-Location).Path |
| 6 | +$log_path = "$current_path/fluentd.log" |
| 7 | + |
| 8 | +ruby bin/fluentd --reg-winsvc i --reg-winsvc-fluentdopt "-c '$default_conf_path' -o '$log_path'" |
| 9 | + |
| 10 | +# Test: must not start automatically |
| 11 | +if ((Get-Service fluentdwinsvc).Status -ne "Stopped") { |
| 12 | + Write-Error "The service should not start automatically." |
| 13 | +} |
| 14 | + |
| 15 | +Start-Service fluentdwinsvc |
| 16 | +Start-Sleep 30 |
| 17 | + |
| 18 | +# Test: the service should be running after started |
| 19 | +if ((Get-Service fluentdwinsvc).Status -ne "Running") { |
| 20 | + Write-Error "The service should be running after started." |
| 21 | +} |
| 22 | + |
| 23 | +# Test: no warn/error/fatal logs |
| 24 | +Get-ChildItem "*.log" | %{ |
| 25 | + Get-Content $_ |
| 26 | + if (Select-String -Path $_ -Pattern "[warn]", "[error]", "[fatal]" -SimpleMatch -Quiet) { |
| 27 | + Select-String -Path $_ -Pattern "[warn]", "[error]", "[fatal]" -SimpleMatch |
| 28 | + Write-Error "There are abnormal level logs in ${_}:" |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +Stop-Service fluentdwinsvc |
| 33 | +Start-Sleep 10 # Somehow it is possible that some processes stay alive for a while. (This could be not good behavior...) |
| 34 | + |
| 35 | +# Test: status after stopped |
| 36 | +if ((Get-Service fluentdwinsvc).Status -ne "Stopped") { |
| 37 | + Write-Error "The service should be in 'Stopped' status after stopped." |
| 38 | +} |
| 39 | +# Test: all Ruby processes should stop |
| 40 | +$ruby_processes = Get-Process -name ruby -ErrorAction SilentlyContinue |
| 41 | +if ($ruby_processes.Count -ne 0) { |
| 42 | + Write-Output $ruby_processes |
| 43 | + Write-Error "All Ruby processes should stop." |
| 44 | +} |
| 45 | + |
| 46 | +# Test: service should stop when the supervisor fails to launch |
| 47 | +# https://github.com/fluent/fluentd/pull/4909 |
| 48 | +$test_setting = @' |
| 49 | +<source> |
| 50 | + @type sample |
| 51 | + @id DUPLICATED_ID |
| 52 | + tag test |
| 53 | +</source> |
| 54 | +<match test> |
| 55 | + @type stdout |
| 56 | + @id DUPLICATED_ID |
| 57 | +</match> |
| 58 | +'@ |
| 59 | +Add-Content -Path "duplicated_id.conf" -Encoding UTF8 -Value $test_setting |
| 60 | +ruby bin/fluentd --reg-winsvc-fluentdopt "-c '$current_path/duplicated_id.conf' -o '$log_path'" |
| 61 | +Start-Service fluentdwinsvc |
| 62 | +Start-Sleep 30 |
| 63 | +if ((Get-Service fluentdwinsvc).Status -ne "Stopped") { |
| 64 | + Write-Error "The service should be in 'Stopped' status when the supervisor fails to launch." |
| 65 | +} |
| 66 | +$ruby_processes = Get-Process -name ruby -ErrorAction SilentlyContinue |
| 67 | +if ($ruby_processes.Count -ne 0) { |
| 68 | + Write-Output $ruby_processes |
| 69 | + Write-Error "All Ruby processes should stop." |
| 70 | +} |
| 71 | + |
| 72 | +ruby bin/fluentd --reg-winsvc u |
| 73 | +Remove-Item $log_path |
0 commit comments