-
Notifications
You must be signed in to change notification settings - Fork 41
Cleanup scripts; allow darwin testing #148
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
Open
aramprice
wants to merge
6
commits into
develop
Choose a base branch
from
cleanup-and-modernize
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfda38a
bin: simplifiy / harmonize scripts
aramprice ad426fd
ci: introduce lint task
aramprice ae5a1dc
Use `tool` directive instead of tools module pattern
aramprice b6cf51b
Cleanup async logger spec
aramprice fa6ef98
Replace call to `nice` with bespoke binary
aramprice 0252e64
Split tests into os-specific files
aramprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
| set -eu -o pipefail | ||
|
|
||
| set -e | ||
| ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
|
||
| bin=$(dirname $0) | ||
| ( | ||
| cd "${ROOT_DIR}" | ||
|
|
||
| if [[ "$GOOS" == 'linux' ]] && [[ "$GOARCH" == 'amd64' ]]; then | ||
| export GOTOOLDIR=$(go env GOROOT)/pkg/linux_amd64 | ||
| fi | ||
|
|
||
| CGO_ENABLED=0 go build -o $bin/../out/verify-multidigest github.com/cloudfoundry/bosh-utils/main | ||
| CGO_ENABLED=0 go build -o out/verify-multidigest github.com/cloudfoundry/bosh-utils/main | ||
| ) |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
| set -eu -o pipefail | ||
|
|
||
| set -e | ||
| ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
|
||
| export GOARCH=amd64 | ||
| export GOOS=linux | ||
| export GOTOOLDIR=$(go env GOROOT)/pkg/linux_amd64 | ||
|
|
||
| $(dirname $0)/build | ||
| "${ROOT_DIR}/bin/build" |
This file contains hidden or 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,23 @@ | ||
| #!/usr/bin/env bash | ||
| set -eu -o pipefail | ||
|
|
||
| ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
|
||
| go_bin_path="$(go env GOBIN)" | ||
| export PATH=${go_bin_path}:${PATH} | ||
| ( | ||
| cd "${ROOT_DIR}" | ||
| if ! command -v golangci-lint &> /dev/null; then | ||
| echo "Installing golangci-lint@latest..." | ||
| go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest | ||
| fi | ||
|
|
||
| golangci-lint version | ||
|
aramprice marked this conversation as resolved.
|
||
|
|
||
| linted_os_list=(linux windows) | ||
|
|
||
| for os in "${linted_os_list[@]}"; do | ||
| echo "lint-ing with GOOS=${os}..." | ||
| GOOS="${os}" golangci-lint run ./... | ||
| done | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
| set -eu -o pipefail | ||
|
|
||
| set -e | ||
| bin=$(dirname $0) | ||
| ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
|
||
| echo -e "\n Testing packages..." | ||
| go run github.com/onsi/ginkgo/v2/ginkgo run -p -r --race --trace --keep-going "${@}" | ||
| ( | ||
| cd "${ROOT_DIR}" | ||
| go run github.com/onsi/ginkgo/v2/ginkgo run -p -r --race --trace --keep-going ${1+"${@}"} | ||
| ) |
This file contains hidden or 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 hidden or 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,6 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -ex | ||
|
|
||
| cd bosh-utils | ||
| bin/lint |
This file contains hidden or 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,8 @@ | ||
| --- | ||
| platform: linux | ||
|
|
||
| inputs: | ||
| - name: bosh-utils | ||
|
|
||
| run: | ||
| path: bosh-utils/ci/tasks/lint.sh |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import ( | |
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| . "github.com/cloudfoundry/bosh-utils/logger" | ||
| "github.com/cloudfoundry/bosh-utils/logger" | ||
| ) | ||
|
|
||
| type intervalWriter struct { | ||
|
|
@@ -52,33 +52,27 @@ func (w *blockingWriter) String() string { | |
| } | ||
|
|
||
| var _ = Describe("Logger", func() { | ||
| var ( | ||
| outBuf = new(bytes.Buffer) | ||
| ) | ||
| BeforeEach(func() { | ||
| outBuf.Reset() | ||
| }) | ||
|
|
||
| Describe("Async Logger", func() { | ||
| It("logs the formatted message to Logger.err at the debug level", func() { | ||
| logger := NewAsyncWriterLogger(LevelDebug, outBuf) | ||
| logger.Debug("TAG", "some %s info to log", "awesome") | ||
| logger.Flush() | ||
| out := new(bytes.Buffer) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
| asyncWriterLogger.Debug("TAG", "some %s info to log", "awesome") | ||
| asyncWriterLogger.Flush() | ||
|
|
||
| expectedContent := expectedLogFormat("TAG", "DEBUG - some awesome info to log") | ||
| Expect(outBuf).To(MatchRegexp(expectedContent)) | ||
| Expect(out).To(MatchRegexp(expectedContent)) | ||
| }) | ||
|
|
||
| It("does not block when its writer is blocked", func() { | ||
| out := new(blockingWriter) | ||
| logger := NewAsyncWriterLogger(LevelDebug, out) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
|
|
||
| out.Lock() | ||
| ch := make(chan struct{}, 1) | ||
| go func() { | ||
| for i := 0; i < 10; i++ { | ||
| logger.Info("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096)) | ||
| logger.Error("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096)) | ||
| for range 10 { | ||
| asyncWriterLogger.Info("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096)) | ||
| asyncWriterLogger.Error("TAG", "Make sure we are not just buffering bytes: %s", strings.Repeat("A", 4096)) | ||
| } | ||
| ch <- struct{}{} | ||
| }() | ||
|
|
@@ -90,46 +84,46 @@ var _ = Describe("Logger", func() { | |
| const s0 = "ABCDEFGHIJ" | ||
| const s1 = "abcdefghij" | ||
|
|
||
| outBuf := new(blockingWriter) | ||
| logger := NewAsyncWriterLogger(LevelDebug, outBuf) | ||
| out := new(blockingWriter) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
|
|
||
| outBuf.Lock() | ||
| logger.Debug("TAG", s0) | ||
| logger.Debug("TAG", s1) | ||
| outBuf.Unlock() | ||
| out.Lock() | ||
| asyncWriterLogger.Debug("TAG", s0) | ||
| asyncWriterLogger.Debug("TAG", s1) | ||
| out.Unlock() | ||
|
|
||
| Expect(logger.Flush()).To(Succeed()) | ||
| Expect(asyncWriterLogger.Flush()).To(Succeed()) | ||
|
|
||
| lines := strings.Split(strings.TrimSpace(outBuf.buf.String()), "\n") | ||
| lines := strings.Split(strings.TrimSpace(out.buf.String()), "\n") | ||
| Expect(lines).To(HaveLen(2)) | ||
| Expect(lines[0]).To(HaveSuffix(s0)) | ||
| Expect(lines[1]).To(HaveSuffix(s1)) | ||
| }) | ||
|
|
||
| It("continuously flushes queued log messages", func() { | ||
| outBuf := new(blockingWriter) | ||
| logger := NewAsyncWriterLogger(LevelDebug, outBuf) | ||
| out := new(blockingWriter) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
|
|
||
| outBuf.Lock() | ||
| for i := 0; i < 10; i++ { | ||
| logger.Debug("TAG", "Queued log message") | ||
| out.Lock() | ||
| for range 10 { | ||
| asyncWriterLogger.Debug("TAG", "Queued log message") | ||
| } | ||
| Expect(outBuf.buf.Len()).To(Equal(0)) | ||
| outBuf.Unlock() | ||
| Eventually(outBuf.Len).ShouldNot(Equal(0)) | ||
| Expect(out.buf.Len()).To(Equal(0)) | ||
| out.Unlock() | ||
| Eventually(out.Len).ShouldNot(Equal(0)) | ||
| }) | ||
|
|
||
| It("flushes with a timeout", func() { | ||
| outBuf := new(blockingWriter) | ||
| logger := NewAsyncWriterLogger(LevelDebug, outBuf) | ||
| logger.Debug("TAG", "something") | ||
| out := new(blockingWriter) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
| asyncWriterLogger.Debug("TAG", "something") | ||
|
|
||
| outBuf.Lock() | ||
| Expect(logger.FlushTimeout(time.Millisecond * 10)).ToNot(Succeed()) | ||
| out.Lock() | ||
| Expect(asyncWriterLogger.FlushTimeout(time.Millisecond * 10)).ToNot(Succeed()) | ||
|
|
||
| outBuf.Unlock() | ||
| Expect(logger.FlushTimeout(time.Millisecond * 10)).To(Succeed()) | ||
| Expect(strings.TrimSpace(outBuf.buf.String())).To(HaveSuffix("something")) | ||
| out.Unlock() | ||
| Expect(asyncWriterLogger.FlushTimeout(time.Millisecond * 10)).To(Succeed()) | ||
| Expect(strings.TrimSpace(out.buf.String())).To(HaveSuffix("something")) | ||
| }) | ||
|
|
||
| It("flush doesn't block writes", func() { | ||
|
|
@@ -140,21 +134,21 @@ var _ = Describe("Logger", func() { | |
| ) | ||
|
|
||
| out := &intervalWriter{dur: WriteInterval} | ||
| logger := NewAsyncWriterLogger(LevelDebug, out) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
|
|
||
| // add some messages to the queue | ||
| out.Lock() | ||
| for i := 0; i < MessageCount; i++ { | ||
| logger.Debug("NEW", "message") | ||
| for range MessageCount { | ||
| asyncWriterLogger.Debug("NEW", "message") | ||
| } | ||
| out.Unlock() | ||
|
|
||
| go logger.Flush() | ||
| go asyncWriterLogger.Flush() | ||
|
|
||
| ch := make(chan struct{}, 1) | ||
| go func() { | ||
| for i := 0; i < MessageCount; i++ { | ||
| logger.Debug("NEW", "message") | ||
| for range MessageCount { | ||
| asyncWriterLogger.Debug("NEW", "message") | ||
| } | ||
| ch <- struct{}{} | ||
| }() | ||
|
|
@@ -169,12 +163,12 @@ var _ = Describe("Logger", func() { | |
| ) | ||
|
|
||
| out := &intervalWriter{dur: WriteInterval} | ||
| logger := NewAsyncWriterLogger(LevelDebug, out) | ||
| asyncWriterLogger := logger.NewAsyncWriterLogger(logger.LevelDebug, out) | ||
|
|
||
| // add some messages to the queue | ||
| out.Lock() | ||
| for i := 0; i < MessageCount; i++ { | ||
| logger.Debug("QUEUED", "queued") | ||
| for range MessageCount { | ||
| asyncWriterLogger.Debug("QUEUED", "queued") | ||
| } | ||
| out.Unlock() | ||
|
|
||
|
|
@@ -183,13 +177,13 @@ var _ = Describe("Logger", func() { | |
| defer tick.Stop() | ||
| go func() { | ||
| for range tick.C { | ||
| logger.Debug("NEW", "new") | ||
| asyncWriterLogger.Debug("NEW", "new") | ||
| } | ||
| }() | ||
|
|
||
| ch := make(chan struct{}, 1) | ||
| go func() { | ||
| logger.Flush() | ||
| asyncWriterLogger.Flush() | ||
| ch <- struct{}{} | ||
| }() | ||
|
|
||
|
|
@@ -200,7 +194,7 @@ var _ = Describe("Logger", func() { | |
| It("prints the correct prefix during concurrent writes", func() { | ||
| ch := make(chan struct{}, 1) | ||
| go func() { | ||
| testConcurrentPrefix(NewAsyncWriterLogger) | ||
| testConcurrentPrefix(logger.NewAsyncWriterLogger) | ||
|
Member
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. New logger with no arguments. Doesn't follow the pattern in the file. Is it intentional? |
||
| ch <- struct{}{} | ||
| }() | ||
| Eventually(ch, time.Second*5).Should(Receive()) | ||
|
|
||
This file contains hidden or 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 hidden or 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,29 @@ | ||
| //go:build !windows | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "runtime" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| func main() { | ||
| time.Sleep(100 * time.Millisecond) | ||
|
|
||
| pid := os.Getpid() | ||
| niceValue, err := syscall.Getpriority(syscall.PRIO_PROCESS, pid) | ||
|
aramprice marked this conversation as resolved.
|
||
| if err != nil { | ||
| fmt.Printf("error getting priority: %s\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Linux: convert knice => unice see https://linux.die.net/man/2/getpriority | ||
| if runtime.GOOS == "linux" { | ||
| fmt.Printf("%d\n", (niceValue-20)*-1) | ||
| } else { | ||
| fmt.Printf("%d\n", niceValue) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 worth pinning to a version to avoid changes to linting causing unexpected failures