-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fixing tests for Windows #2927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing tests for Windows #2927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
.*.swo | ||
*.iml | ||
.idea | ||
tags | ||
|
||
/prometheus | ||
/promtool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2017 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build !windows | ||
|
||
package config | ||
|
||
const ruleFilesConfigFile = "testdata/rules_abs_path.good.yml" | ||
|
||
var ruleFilesExpectedConf = &Config{ | ||
GlobalConfig: DefaultGlobalConfig, | ||
RuleFiles: []string{ | ||
"testdata/first.rules", | ||
"testdata/rules/second.rules", | ||
"/absolute/third.rules", | ||
}, | ||
original: "", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2017 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
const ruleFilesConfigFile = "testdata/rules_abs_path_windows.good.yml" | ||
|
||
var ruleFilesExpectedConf = &Config{ | ||
GlobalConfig: DefaultGlobalConfig, | ||
RuleFiles: []string{ | ||
"testdata\\first.rules", | ||
"testdata\\rules\\second.rules", | ||
"c:\\absolute\\third.rules", | ||
}, | ||
original: "", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ global: | |
|
||
rule_files: | ||
- "first.rules" | ||
- "/absolute/second.rules" | ||
- "my/*.rules" | ||
|
||
remote_write: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rule_files: | ||
- 'first.rules' | ||
- 'rules/second.rules' | ||
- '/absolute/third.rules' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rule_files: | ||
- 'first.rules' | ||
- 'rules\second.rules' | ||
- 'c:\absolute\third.rules' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ const ( | |
|
||
// NilCloser is a no-op Closer. | ||
NilCloser = nilCloser(true) | ||
|
||
// The number of times that a TemporaryDirectory will retry its removal | ||
temporaryDirectoryRemoveRetries = 2 | ||
) | ||
|
||
type ( | ||
|
@@ -84,15 +87,20 @@ func NewCallbackCloser(fn func()) Closer { | |
} | ||
|
||
func (t temporaryDirectory) Close() { | ||
retries := temporaryDirectoryRemoveRetries | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the retrying actually help in practice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it helps. In a Windows machine, the promql tests always fail due to RemoveAll() can't remove a directory because is not empty. The strange thing is that if you go to the offending directory after the tests finished, the directory is actually empty. |
||
err := os.RemoveAll(t.path) | ||
if err != nil { | ||
for err != nil && retries > 0 { | ||
switch { | ||
case os.IsNotExist(err): | ||
return | ||
err = nil | ||
default: | ||
t.tester.Fatal(err) | ||
retries-- | ||
err = os.RemoveAll(t.path) | ||
} | ||
} | ||
if err != nil { | ||
t.tester.Fatal(err) | ||
} | ||
} | ||
|
||
func (t temporaryDirectory) Path() string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for me 😉, I use Exuberant CTags during development to navigate the code. I can remove this if you like.