Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
ac5b5d39
Commit
ac5b5d39
authored
1 year ago
by
Semyon Krestyaninov
Browse files
Options
Downloads
Patches
Plain Diff
refactor tests and fix events
parent
5aa0842b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
log/zap/buffered_write_syncer_test.go
+9
-21
9 additions, 21 deletions
log/zap/buffered_write_syncer_test.go
log/zap/core_test.go
+8
-8
8 additions, 8 deletions
log/zap/core_test.go
log/zap/example_test.go
+12
-12
12 additions, 12 deletions
log/zap/example_test.go
with
29 additions
and
41 deletions
log/zap/buffered_write_syncer_test.go
+
9
−
21
View file @
ac5b5d39
...
...
@@ -53,16 +53,12 @@ func TestBufferedWriteSyncer_Write_Concurrent(t *testing.T) {
wg
.
Add
(
1
)
go
func
(
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
}(
&
wg
)
}
wg
.
Wait
()
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Stop
())
service
.
AssertExpectations
(
t
)
}
...
...
@@ -81,15 +77,12 @@ func TestBufferedWriteSyncer_Flush(t *testing.T) {
for
i
:=
0
;
i
<
10
;
i
++
{
for
j
:=
0
;
j
<
10
;
j
++
{
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
}
err
:=
ws
.
Sync
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Sync
())
}
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Stop
())
service
.
AssertExpectations
(
t
)
}
...
...
@@ -107,12 +100,10 @@ func TestBufferedWriteSyncer_MaxBufferSize(t *testing.T) {
ws
:=
&
BufferedWriteSyncer
{
Service
:
service
,
MaxBufferSize
:
10
}
for
i
:=
0
;
i
<
100
;
i
++
{
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
}
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Stop
())
service
.
AssertExpectations
(
t
)
}
...
...
@@ -130,14 +121,11 @@ func TestBufferedWriteSyncer_FlushInterval(t *testing.T) {
ws
:=
&
BufferedWriteSyncer
{
Service
:
service
,
FlushInterval
:
time
.
Second
}
for
j
:=
0
;
j
<
10
;
j
++
{
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
}
time
.
Sleep
(
3
*
time
.
Second
)
// ждем, пока сработает интервал
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
ws
.
Stop
())
service
.
AssertExpectations
(
t
)
}
This diff is collapsed.
Click to expand it.
log/zap/core_test.go
+
8
−
8
View file @
ac5b5d39
...
...
@@ -5,7 +5,7 @@ import (
"git.perx.ru/perxis/perxis-go/id"
"git.perx.ru/perxis/perxis-go/log"
zap
2
"git.perx.ru/perxis/perxis-go/zap"
log
zap
"git.perx.ru/perxis/perxis-go/zap"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
...
...
@@ -31,13 +31,13 @@ func TestCore_getEntry(t *testing.T) {
entry
:
zapcore
.
Entry
{
Level
:
zapcore
.
InfoLevel
,
Message
:
"создан элемент коллекции"
},
fields
:
[]
zapcore
.
Field
{
zap
.
String
(
"key"
,
"val"
),
// будет проигнорировано
zap
2
.
Category
(
"create"
),
zap
2
.
Component
(
"Items.Service"
),
zap
2
.
Event
(
"Items.Create"
),
zap
2
.
Object
(
"/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"
),
zap
2
.
Caller
(
"/users/PHVz"
),
zap
2
.
Attr
(
"any"
),
zap
2
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
log
zap
.
Category
(
"create"
),
log
zap
.
Component
(
"Items.Service"
),
log
zap
.
Event
(
"Items.Create"
),
log
zap
.
Object
(
"/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"
),
log
zap
.
Caller
(
"/users/PHVz"
),
log
zap
.
Attr
(
"any"
),
log
zap
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
},
},
want
:
&
log
.
Entry
{
...
...
This diff is collapsed.
Click to expand it.
log/zap/example_test.go
+
12
−
12
View file @
ac5b5d39
...
...
@@ -13,7 +13,7 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/items"
"git.perx.ru/perxis/perxis-go/pkg/users"
usersmocks
"git.perx.ru/perxis/perxis-go/pkg/users/mocks"
zap
2
"git.perx.ru/perxis/perxis-go/zap"
log
zap
"git.perx.ru/perxis/perxis-go/zap"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
...
...
@@ -29,7 +29,7 @@ func TestExample(t *testing.T) {
LogLevel
:
log
.
Level
(
zapcore
.
InfoLevel
),
Message
:
"Successfully created"
,
Component
:
"Items"
,
Event
:
items
.
EventCreate
Item
,
Event
:
items
.
Event
Item
Create
,
ObjectID
:
id
.
MustObjectId
(
item
),
CallerID
:
id
.
MustObjectId
(
user
),
Tags
:
[]
string
{
"tag1"
,
"tag2"
,
"tag3"
},
...
...
@@ -38,7 +38,7 @@ func TestExample(t *testing.T) {
LogLevel
:
log
.
Level
(
zapcore
.
WarnLevel
),
Message
:
"Successfully updated"
,
Component
:
"Items"
,
Event
:
items
.
EventUpdate
Item
,
Event
:
items
.
Event
Item
Update
,
ObjectID
:
id
.
MustObjectId
(
item
),
CallerID
:
id
.
MustObjectId
(
user
),
Attr
:
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}},
...
...
@@ -70,23 +70,23 @@ func TestExample(t *testing.T) {
// Пример отправки логов для сервиса Items
{
logger
:=
logger
.
With
(
zap
2
.
Component
(
"Items"
))
logger
:=
logger
.
With
(
log
zap
.
Component
(
"Items"
))
ctx
:=
auth
.
WithPrincipal
(
context
.
Background
(),
factory
.
User
(
"74d90aaf"
))
// Отправка лога при создании item
logger
.
Info
(
"Successfully created"
,
zap
2
.
Event
(
items
.
EventCreate
Item
),
zap
2
.
Object
(
item
),
zap
2
.
CallerFromContext
(
ctx
),
zap
2
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
log
zap
.
Event
(
items
.
Event
Item
Create
),
log
zap
.
Object
(
item
),
log
zap
.
CallerFromContext
(
ctx
),
log
zap
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
)
// Отправка лога при обновлении item
logger
.
Warn
(
"Successfully updated"
,
zap
2
.
Event
(
items
.
EventUpdate
Item
),
zap
2
.
Object
(
item
),
zap
2
.
CallerFromContext
(
ctx
),
zap
2
.
Attr
(
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}}),
log
zap
.
Event
(
items
.
Event
Item
Update
),
log
zap
.
Object
(
item
),
log
zap
.
CallerFromContext
(
ctx
),
log
zap
.
Attr
(
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}}),
)
}
...
...
This diff is collapsed.
Click to expand it.
Semyon Krestyaninov
@krestyaninov
mentioned in commit
0f4952c3
·
1 year ago
mentioned in commit
0f4952c3
mentioned in commit 0f4952c3cbd6b0ae7ecbb92228450520659617d7
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment