-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
counter: avoid the rotation timer in counter.Open
As observed in golang/go#68497, scheduling a rotation timer can break runtime deadlock detection (all goroutines are asleep...). Furthermore, for short-lived processes such as command line tools, there is no reason to schedule a file rotation. Therefore, change the default behavior of counter.Open not to rotate the counter file, and introduce a new OpenAndRotate API to be used by gopls. For golang/go#68497 Change-Id: I7929c2d622d15e36ca99036d8c7eac1eed8fabf5 Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/599075 Auto-Submit: Robert Findley <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
4 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package counter_test | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"golang.org/x/telemetry/counter" | ||
"golang.org/x/telemetry/internal/telemetry" | ||
"golang.org/x/telemetry/internal/testenv" | ||
) | ||
|
||
const telemetryDirEnvVar = "_COUNTER_TEST_TELEMETRY_DIR" | ||
|
||
func TestMain(m *testing.M) { | ||
if dir := os.Getenv(telemetryDirEnvVar); dir != "" { | ||
// Run for TestOpenAPIMisuse. | ||
telemetry.Default = telemetry.NewDir(dir) | ||
counter.Open() | ||
counter.OpenAndRotate() // should panic | ||
os.Exit(0) | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestOpenAPIMisuse(t *testing.T) { | ||
testenv.SkipIfUnsupportedPlatform(t) | ||
|
||
// Test that Open and OpenAndRotate cannot be used simultaneously. | ||
exe, err := os.Executable() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cmd := exec.Command(exe) | ||
cmd.Env = append(os.Environ(), telemetryDirEnvVar+"="+t.TempDir()) | ||
|
||
if err := cmd.Run(); err == nil { | ||
t.Error("Failed to detect API misuse: no error from calling both Open and OpenAndRotate") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters