Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5d10dcd9
Commit
5d10dcd9
authored
Dec 24, 2017
by
vikaschoudhary16
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove redundant sleep from ReRegistration unit test case
parent
572e2764
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
20 deletions
+9
-20
manager_test.go
pkg/kubelet/cm/deviceplugin/manager_test.go
+9
-20
No files found.
pkg/kubelet/cm/deviceplugin/manager_test.go
View file @
5d10dcd9
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"reflect"
"reflect"
"sync/atomic"
"sync/atomic"
"testing"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -68,36 +67,29 @@ func TestDevicePluginReRegistration(t *testing.T) {
...
@@ -68,36 +67,29 @@ func TestDevicePluginReRegistration(t *testing.T) {
{
ID
:
"Dev3"
,
Health
:
pluginapi
.
Healthy
},
{
ID
:
"Dev3"
,
Health
:
pluginapi
.
Healthy
},
}
}
callbackCount
:=
0
expCallbackCount
:=
int32
(
0
)
callbackChan
:=
make
(
chan
int
)
callbackCount
:=
int32
(
0
)
var
stopping
int32
callbackChan
:=
make
(
chan
int32
)
stopping
=
0
callback
:=
func
(
n
string
,
a
,
u
,
r
[]
pluginapi
.
Device
)
{
callback
:=
func
(
n
string
,
a
,
u
,
r
[]
pluginapi
.
Device
)
{
// Should be called three times, one for each plugin registration, till we are stopping.
callbackCount
++
if
callbackCount
>
2
&&
atomic
.
LoadInt32
(
&
stopping
)
<=
0
{
if
callbackCount
>
atomic
.
LoadInt32
(
&
expCallbackCount
)
{
t
.
FailNow
()
t
.
FailNow
()
}
}
callbackCount
++
callbackChan
<-
callbackCount
callbackChan
<-
callbackCount
}
}
m
,
p1
:=
setup
(
t
,
devs
,
callback
)
m
,
p1
:=
setup
(
t
,
devs
,
callback
)
atomic
.
StoreInt32
(
&
expCallbackCount
,
1
)
p1
.
Register
(
socketName
,
testResourceName
)
p1
.
Register
(
socketName
,
testResourceName
)
// Wait for the first callback to be issued.
// Wait for the first callback to be issued.
<-
callbackChan
<-
callbackChan
// Wait till the endpoint is added to the manager.
for
i
:=
0
;
i
<
20
;
i
++
{
if
len
(
m
.
Devices
())
>
0
{
break
}
time
.
Sleep
(
1
)
}
devices
:=
m
.
Devices
()
devices
:=
m
.
Devices
()
require
.
Equal
(
t
,
2
,
len
(
devices
[
testResourceName
]),
"Devices are not updated."
)
require
.
Equal
(
t
,
2
,
len
(
devices
[
testResourceName
]),
"Devices are not updated."
)
p2
:=
NewDevicePluginStub
(
devs
,
pluginSocketName
+
".new"
)
p2
:=
NewDevicePluginStub
(
devs
,
pluginSocketName
+
".new"
)
err
:=
p2
.
Start
()
err
:=
p2
.
Start
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
atomic
.
StoreInt32
(
&
expCallbackCount
,
2
)
p2
.
Register
(
socketName
,
testResourceName
)
p2
.
Register
(
socketName
,
testResourceName
)
// Wait for the second callback to be issued.
// Wait for the second callback to be issued.
<-
callbackChan
<-
callbackChan
...
@@ -109,20 +101,17 @@ func TestDevicePluginReRegistration(t *testing.T) {
...
@@ -109,20 +101,17 @@ func TestDevicePluginReRegistration(t *testing.T) {
p3
:=
NewDevicePluginStub
(
devsForRegistration
,
pluginSocketName
+
".third"
)
p3
:=
NewDevicePluginStub
(
devsForRegistration
,
pluginSocketName
+
".third"
)
err
=
p3
.
Start
()
err
=
p3
.
Start
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
atomic
.
StoreInt32
(
&
expCallbackCount
,
3
)
p3
.
Register
(
socketName
,
testResourceName
)
p3
.
Register
(
socketName
,
testResourceName
)
// Wait for the second callback to be issued.
// Wait for the second callback to be issued.
<-
callbackChan
<-
callbackChan
devices3
:=
m
.
Devices
()
devices3
:=
m
.
Devices
()
require
.
Equal
(
t
,
1
,
len
(
devices3
[
testResourceName
]),
"Devices of plugin previously registered should be removed."
)
require
.
Equal
(
t
,
1
,
len
(
devices3
[
testResourceName
]),
"Devices of plugin previously registered should be removed."
)
// Wait long enough to catch unexpected callbacks.
time
.
Sleep
(
5
*
time
.
Second
)
atomic
.
StoreInt32
(
&
stopping
,
1
)
p2
.
Stop
()
p2
.
Stop
()
p3
.
Stop
()
p3
.
Stop
()
cleanup
(
t
,
m
,
p1
)
cleanup
(
t
,
m
,
p1
)
close
(
callbackChan
)
}
}
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
monitorCallback
)
(
Manager
,
*
Stub
)
{
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
monitorCallback
)
(
Manager
,
*
Stub
)
{
...
...
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