Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a6265cb4
Commit
a6265cb4
authored
Oct 14, 2014
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethlog: verify that Flush is blocking in TestLoggerFlush
parent
793baf06
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
loggers_test.go
ethlog/loggers_test.go
+24
-6
No files found.
ethlog/loggers_test.go
View file @
a6265cb4
...
...
@@ -49,22 +49,40 @@ func (ls *TestLogSystem) CheckOutput(t *testing.T, expected string) {
}
}
type
blockedLogSystem
struct
{
LogSystem
unblock
chan
struct
{}
}
func
(
ls
blockedLogSystem
)
Println
(
v
...
interface
{})
{
<-
ls
.
unblock
ls
.
LogSystem
.
Println
(
v
...
)
}
func
(
ls
blockedLogSystem
)
Printf
(
fmt
string
,
v
...
interface
{})
{
<-
ls
.
unblock
ls
.
LogSystem
.
Printf
(
fmt
,
v
...
)
}
func
TestLoggerFlush
(
t
*
testing
.
T
)
{
Reset
()
logger
:=
NewLogger
(
"TEST"
)
testLogSystem
:=
&
TestLogSystem
{
level
:
WarnLevel
}
AddLogSystem
(
testLogSystem
)
ls
:=
blockedLogSystem
{
&
TestLogSystem
{
level
:
WarnLevel
},
make
(
chan
struct
{})
}
AddLogSystem
(
ls
)
for
i
:=
0
;
i
<
5
;
i
++
{
// these writes shouldn't hang even though ls is blocked
logger
.
Errorf
(
"."
)
}
Flush
()
output
:=
testLogSystem
.
Output
if
output
!=
"[TEST] .[TEST] .[TEST] .[TEST] .[TEST] ."
{
t
.
Error
(
"Expected complete logger output '[TEST] .[TEST] .[TEST] .[TEST] .[TEST] .', got "
,
output
)
beforeFlush
:=
time
.
Now
()
time
.
AfterFunc
(
80
*
time
.
Millisecond
,
func
()
{
close
(
ls
.
unblock
)
})
Flush
()
// this should hang for approx. 80ms
if
blockd
:=
time
.
Now
()
.
Sub
(
beforeFlush
);
blockd
<
80
*
time
.
Millisecond
{
t
.
Errorf
(
"Flush didn't block long enough, blocked for %v, should've been >= 80ms"
,
blockd
)
}
ls
.
LogSystem
.
(
*
TestLogSystem
)
.
CheckOutput
(
t
,
"[TEST] .[TEST] .[TEST] .[TEST] .[TEST] ."
)
}
func
TestLoggerPrintln
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment