forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from suyuan32/dev
Dev
- Loading branch information
Showing
24 changed files
with
1,012 additions
and
192 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
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,36 @@ | ||
package prof | ||
|
||
import ( | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDisplayStats(t *testing.T) { | ||
writer := &threadSafeBuffer{ | ||
buf: strings.Builder{}, | ||
} | ||
displayStatsWithWriter(writer, time.Millisecond*10) | ||
time.Sleep(time.Millisecond * 50) | ||
assert.Contains(t, writer.String(), "Goroutines: ") | ||
} | ||
|
||
type threadSafeBuffer struct { | ||
buf strings.Builder | ||
lock sync.Mutex | ||
} | ||
|
||
func (b *threadSafeBuffer) String() string { | ||
b.lock.Lock() | ||
defer b.lock.Unlock() | ||
return b.buf.String() | ||
} | ||
|
||
func (b *threadSafeBuffer) Write(p []byte) (n int, err error) { | ||
b.lock.Lock() | ||
defer b.lock.Unlock() | ||
return b.buf.Write(p) | ||
} |
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,27 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRunningInUserNS(t *testing.T) { | ||
// should be false in docker | ||
assert.False(t, runningInUserNS()) | ||
} | ||
|
||
func TestCgroupV1(t *testing.T) { | ||
if isCgroup2UnifiedMode() { | ||
cg, err := currentCgroupV1() | ||
assert.NoError(t, err) | ||
_, err = cg.cpus() | ||
assert.Error(t, err) | ||
_, err = cg.cpuPeriodUs() | ||
assert.Error(t, err) | ||
_, err = cg.cpuQuotaUs() | ||
assert.Error(t, err) | ||
_, err = cg.usageAllCpus() | ||
assert.Error(t, err) | ||
} | ||
} |
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
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,28 @@ | ||
package cache | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCacheOptions(t *testing.T) { | ||
t.Run("default options", func(t *testing.T) { | ||
o := newOptions() | ||
assert.Equal(t, defaultExpiry, o.Expiry) | ||
assert.Equal(t, defaultNotFoundExpiry, o.NotFoundExpiry) | ||
}) | ||
|
||
t.Run("with expiry", func(t *testing.T) { | ||
o := newOptions(WithExpiry(time.Second)) | ||
assert.Equal(t, time.Second, o.Expiry) | ||
assert.Equal(t, defaultNotFoundExpiry, o.NotFoundExpiry) | ||
}) | ||
|
||
t.Run("with not found expiry", func(t *testing.T) { | ||
o := newOptions(WithNotFoundExpiry(time.Second)) | ||
assert.Equal(t, defaultExpiry, o.Expiry) | ||
assert.Equal(t, time.Second, o.NotFoundExpiry) | ||
}) | ||
} |
Oops, something went wrong.