Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
3b4c09e4
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3b4c09e4
编写于
9月 28, 2015
作者:
V
Valentina Armenise
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[JENKINS-30084] enhancing test case
上级
e33f3f62
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
17 deletion
+57
-17
core/src/main/java/hudson/model/Queue.java
core/src/main/java/hudson/model/Queue.java
+7
-0
test/src/test/java/hudson/model/QueueTest.java
test/src/test/java/hudson/model/QueueTest.java
+33
-8
test/src/test/java/hudson/slaves/DummyCloudImpl.java
test/src/test/java/hudson/slaves/DummyCloudImpl.java
+17
-9
未找到文件。
core/src/main/java/hudson/model/Queue.java
浏览文件 @
3b4c09e4
...
...
@@ -876,6 +876,13 @@ public class Queue extends ResourceController implements Saveable {
return
new
ArrayList
<
BuildableItem
>(
snapshot
.
pendings
);
}
/**
* Gets the snapshot of all {@link BlockedItem}s.
*/
public
List
<
BlockedItem
>
getBlockedItems
()
{
return
new
ArrayList
<
BlockedItem
>(
snapshot
.
blockedProjects
);
}
/**
* Returns the snapshot of all {@link LeftItem}s.
*
...
...
test/src/test/java/hudson/model/QueueTest.java
浏览文件 @
3b4c09e4
...
...
@@ -100,6 +100,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.jvnet.hudson.test.Issue
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.MockQueueItemAuthenticator
;
import
org.jvnet.hudson.test.SequenceLock
;
import
org.jvnet.hudson.test.SleepBuilder
;
import
org.jvnet.hudson.test.TestBuilder
;
...
...
@@ -807,8 +808,9 @@ public class QueueTest {
}
@Test
public
void
shouldBeAbleToBlockFly
WeightTaskOn
LastMinute
()
throws
Exception
{
public
void
shouldBeAbleToBlockFly
weightTaskAtThe
LastMinute
()
throws
Exception
{
MatrixProject
matrixProject
=
r
.
createMatrixProject
(
"downstream"
);
matrixProject
.
setDisplayName
(
"downstream"
);
matrixProject
.
setAxes
(
new
AxisList
(
new
Axis
(
"axis"
,
"a"
,
"b"
)
));
...
...
@@ -827,19 +829,42 @@ public class QueueTest {
//we schedule the project but we pretend no executors are available thus
//the flyweight task is in the buildable queue without being executed
matrixProject
.
scheduleBuild2
(
0
);
//let s wait for the Queue instance to be updated
while
(
Queue
.
getInstance
().
getBuildableItems
().
size
()
!=
1
)
{
Thread
.
sleep
(
10
);
}
//in this state the build is not blocked, it's just waiting for an available executor
assertFalse
(
matrixProject
.
isBuildBlocked
());
assertFalse
(
Queue
.
getInstance
().
getItem
(
1
).
isBlocked
());
//we start the upstream project that should block the downstream one
upstreamProject
.
getBuildersList
().
add
(
new
SleepBuilder
(
10000
));
upstreamProject
.
setDisplayName
(
"upstream"
);
QueueTaskFuture
upstream
=
upstreamProject
.
scheduleBuild2
(
0
);
upstream
.
waitForStart
();
//let's wait for the Queue to be updated
Thread
.
sleep
(
5000
);
//the downstream project is blocked waiting for the upstream to finish
assertTrue
(
matrixProject
.
isBuildBlocked
());
//let s wait for the Upstream to enter the buildable Queue
boolean
enteredTheQueue
=
false
;
while
(!
enteredTheQueue
)
{
for
(
Queue
.
BuildableItem
item
:
Queue
.
getInstance
().
getBuildableItems
())
{
if
(
item
.
task
.
getDisplayName
()
!=
null
&&
item
.
task
.
getDisplayName
().
equals
(
upstreamProject
.
getDisplayName
()))
{
enteredTheQueue
=
true
;
}
}
}
//let's wait for the upstream project to actually start so that we're sure the Queue has been updated
//when the upstream starts the downstream has already left the buildable queue and the queue is empty
while
(!
Queue
.
getInstance
().
getBuildableItems
().
isEmpty
())
{
Thread
.
sleep
(
10
);
}
assertTrue
(
Queue
.
getInstance
().
getItem
(
1
).
isBlocked
());
assertTrue
(
Queue
.
getInstance
().
getBlockedItems
().
get
(
0
).
task
.
getDisplayName
().
equals
(
matrixProject
.
displayName
));
r
.
assertBuildStatusSuccess
(
upstream
);
//once the upstream is completed, the downstream can leave the buildable queue.
assertFalse
(
matrixProject
.
isBuildBlocked
());
//once the upstream is completed, the downstream can join the buildable queue again.
while
(
Queue
.
getInstance
().
getBuildableItems
().
isEmpty
())
{
Thread
.
sleep
(
10
);
}
assertFalse
(
Queue
.
getInstance
().
getItem
(
1
).
isBlocked
());
assertTrue
(
Queue
.
getInstance
().
getBlockedItems
().
isEmpty
());
assertTrue
(
Queue
.
getInstance
().
getBuildableItems
().
get
(
0
).
task
.
getDisplayName
().
equals
(
matrixProject
.
displayName
));
}
//let's make sure that the downstram project is not started before the upstream --> we want to simulate
...
...
test/src/test/java/hudson/slaves/DummyCloudImpl.java
浏览文件 @
3b4c09e4
...
...
@@ -39,6 +39,8 @@ import hudson.util.DescribableList;
import
jenkins.model.Jenkins
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
javax.xml.ws.Provider
;
/**
* {@link Cloud} implementation useful for testing.
*
...
...
@@ -67,15 +69,12 @@ public class DummyCloudImpl extends Cloud {
*/
public
Label
label
;
public
void
setNodeProperties
(
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>
nodeProperties
)
{
this
.
nodeProperties
=
nodeProperties
;
}
public
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>
getNodeProperties
()
{
public
List
<
NodeProperty
<?>>
getNodeProperties
()
{
return
this
.
nodeProperties
;
}
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>
nodeProperties
=
new
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>(
Jenkins
.
getInstance
().
getNodesObject
()
);
List
<
NodeProperty
<?>
>
nodeProperties
=
new
ArrayList
<
NodeProperty
<?>>(
);
public
DummyCloudImpl
(
JenkinsRule
rule
,
int
delay
)
{
super
(
"test"
);
...
...
@@ -83,7 +82,7 @@ public class DummyCloudImpl extends Cloud {
this
.
delay
=
delay
;
}
public
DummyCloudImpl
(
JenkinsRule
rule
,
int
delay
,
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>
nodeProperties
)
{
public
DummyCloudImpl
(
JenkinsRule
rule
,
int
delay
,
List
<
NodeProperty
<?>
>
nodeProperties
)
{
super
(
"test"
);
this
.
rule
=
rule
;
this
.
delay
=
delay
;
...
...
@@ -125,8 +124,17 @@ public class DummyCloudImpl extends Cloud {
Thread
.
sleep
(
time
);
System
.
out
.
println
(
"launching slave"
);
DumbSlave
slave
=
rule
.
createSlave
(
label
);
slave
.
getNodeProperties
().
addAll
(
nodeProperties
);
final
DumbSlave
slave
=
rule
.
createSlave
(
label
);
Provider
<
NodeProperty
>
nodePropertyProvider
=
new
Provider
<
NodeProperty
>()
{
@Override
public
NodeProperty
invoke
(
NodeProperty
request
)
{
request
.
setNode
(
slave
);
return
request
;
}
};
for
(
NodeProperty
nodeProperty
:
nodeProperties
)
{
slave
.
getNodeProperties
().
add
(
nodePropertyProvider
.
invoke
(
nodeProperty
));
}
computer
=
slave
.
toComputer
();
computer
.
connect
(
false
).
get
();
synchronized
(
DummyCloudImpl
.
this
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录