Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
3fa11bd4
Commit
3fa11bd4
authored
11 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
Dont use exceptions for the backgroundjob test cases
parent
4f4ad724
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/lib/backgroundjob/queuedjob.php
+21
-9
21 additions, 9 deletions
tests/lib/backgroundjob/queuedjob.php
tests/lib/backgroundjob/timedjob.php
+25
-26
25 additions, 26 deletions
tests/lib/backgroundjob/timedjob.php
with
46 additions
and
35 deletions
tests/lib/backgroundjob/queuedjob.php
+
21
−
9
View file @
3fa11bd4
...
...
@@ -9,8 +9,17 @@
namespace
Test\BackgroundJob
;
class
TestQueuedJob
extends
\OC\BackgroundJob\QueuedJob
{
private
$testCase
;
/**
* @param QueuedJob $testCase
*/
public
function
__construct
(
$testCase
)
{
$this
->
testCase
=
$testCase
;
}
public
function
run
(
$argument
)
{
th
row
new
JobRun
();
//throw an exception so we can detect if this function is called
$
th
is
->
testCase
->
markRun
();
}
}
...
...
@@ -24,19 +33,22 @@ class QueuedJob extends \PHPUnit_Framework_TestCase {
*/
private
$job
;
private
$jobRun
=
false
;
public
function
markRun
()
{
$this
->
jobRun
=
true
;
}
public
function
setup
()
{
$this
->
jobList
=
new
DummyJobList
();
$this
->
job
=
new
TestQueuedJob
();
$this
->
job
=
new
TestQueuedJob
(
$this
);
$this
->
jobList
->
add
(
$this
->
job
);
$this
->
jobRun
=
false
;
}
public
function
testJobShouldBeRemoved
()
{
try
{
$this
->
assertTrue
(
$this
->
jobList
->
has
(
$this
->
job
,
null
));
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
fail
(
"job should have been run"
);
}
catch
(
JobRun
$e
)
{
$this
->
assertFalse
(
$this
->
jobList
->
has
(
$this
->
job
,
null
));
}
$this
->
assertTrue
(
$this
->
jobList
->
has
(
$this
->
job
,
null
));
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
assertTrue
(
$this
->
jobRun
);
}
}
This diff is collapsed.
Click to expand it.
tests/lib/backgroundjob/timedjob.php
+
25
−
26
View file @
3fa11bd4
...
...
@@ -9,12 +9,18 @@
namespace
Test\BackgroundJob
;
class
TestTimedJob
extends
\OC\BackgroundJob\TimedJob
{
public
function
__construct
()
{
private
$testCase
;
/**
* @param TimedJob $testCase
*/
public
function
__construct
(
$testCase
)
{
$this
->
setInterval
(
10
);
$this
->
testCase
=
$testCase
;
}
public
function
run
(
$argument
)
{
th
row
new
JobRun
();
//throw an exception so we can detect if this function is called
$
th
is
->
testCase
->
markRun
();
}
}
...
...
@@ -28,44 +34,37 @@ class TimedJob extends \PHPUnit_Framework_TestCase {
*/
private
$job
;
private
$jobRun
=
false
;
public
function
markRun
()
{
$this
->
jobRun
=
true
;
}
public
function
setup
()
{
$this
->
jobList
=
new
DummyJobList
();
$this
->
job
=
new
TestTimedJob
();
$this
->
job
=
new
TestTimedJob
(
$this
);
$this
->
jobList
->
add
(
$this
->
job
);
$this
->
jobRun
=
false
;
}
public
function
testShouldRunAfterInterval
()
{
$this
->
job
->
setLastRun
(
time
()
-
12
);
try
{
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
fail
(
"job should have run"
);
}
catch
(
JobRun
$e
)
{
}
$this
->
assertTrue
(
true
);
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
assertTrue
(
$this
->
jobRun
);
}
public
function
testShouldNotRunWithinInterval
()
{
$this
->
job
->
setLastRun
(
time
()
-
5
);
try
{
$this
->
job
->
execute
(
$this
->
jobList
);
}
catch
(
JobRun
$e
)
{
$this
->
fail
(
"job should not have run"
);
}
$this
->
assertTrue
(
true
);
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
assertFalse
(
$this
->
jobRun
);
}
public
function
testShouldNotTwice
()
{
$this
->
job
->
setLastRun
(
time
()
-
15
);
try
{
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
fail
(
"job should have run the first time"
);
}
catch
(
JobRun
$e
)
{
try
{
$this
->
job
->
execute
(
$this
->
jobList
);
}
catch
(
JobRun
$e
)
{
$this
->
fail
(
"job should not have run the second time"
);
}
}
$this
->
assertTrue
(
true
);
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
assertTrue
(
$this
->
jobRun
);
$this
->
jobRun
=
false
;
$this
->
job
->
execute
(
$this
->
jobList
);
$this
->
assertFalse
(
$this
->
jobRun
);
}
}
This diff is collapsed.
Click to expand it.
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