Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testcenter-frontend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
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
IQB
discontinued
testcenter-frontend
Commits
321324f0
Commit
321324f0
authored
4 years ago
by
paf
Browse files
Options
Downloads
Patches
Plain Diff
make command service ready to put commandSubscription (and command reactions) somewhere else
parent
27fe616d
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
src/app/shared/websocket-backend.service.ts
+4
-4
4 additions, 4 deletions
src/app/shared/websocket-backend.service.ts
src/app/test-controller/command.service.ts
+52
-57
52 additions, 57 deletions
src/app/test-controller/command.service.ts
with
56 additions
and
61 deletions
src/app/shared/websocket-backend.service.ts
+
4
−
4
View file @
321324f0
...
...
@@ -8,10 +8,10 @@ import {WebsocketService} from './websocket.service';
export
type
ConnectionStatus
=
'
initial
'
|
'
ws-offline
'
|
'
ws-online
'
|
'
polling-sleep
'
|
'
polling-fetch
'
|
'
error
'
;
export
abstract
class
WebsocketBackendService
<
T
>
extends
WebsocketService
implements
OnDestroy
{
abstract
pollingEndpoint
:
string
;
abstract
pollingInterval
:
number
;
abstract
wsChannelName
:
string
;
abstract
initialData
:
T
;
protected
abstract
pollingEndpoint
:
string
;
protected
abstract
pollingInterval
:
number
;
protected
abstract
wsChannelName
:
string
;
protected
abstract
initialData
:
T
;
public
data$
:
BehaviorSubject
<
T
>
;
public
connectionStatus$
:
BehaviorSubject
<
ConnectionStatus
>
=
new
BehaviorSubject
<
ConnectionStatus
>
(
'
initial
'
);
...
...
This diff is collapsed.
Click to expand it.
src/app/test-controller/command.service.ts
+
52
−
57
View file @
321324f0
import
{
Inject
,
Injectable
,
OnDestroy
}
from
'
@angular/core
'
;
import
{
of
,
Subject
,
Subscription
,
timer
}
from
'
rxjs
'
;
import
{
Observable
,
of
,
Subject
,
Subscription
,
timer
}
from
'
rxjs
'
;
import
{
Command
,
commandKeywords
,
isKnownCommand
,
TestStatus
}
from
'
./test-controller.interfaces
'
;
import
{
TestControllerService
}
from
'
./test-controller.service
'
;
import
{
...
...
@@ -20,11 +20,22 @@ type TestStartedOrStopped = 'started' | 'terminated' | '';
@
Injectable
()
export
class
CommandService
extends
WebsocketBackendService
<
Command
[]
>
implements
OnDestroy
{
public
command$
:
Observable
<
Command
>
;
protected
initialData
=
[];
protected
pollingEndpoint
=
''
;
protected
pollingInterval
=
5000
;
protected
wsChannelName
=
'
commands
'
;
private
commandReceived$
:
Subject
<
Command
>
=
new
Subject
<
Command
>
();
private
commandSubscription
:
Subscription
;
private
testStartedSubscription
:
Subscription
;
constructor
(
@
Inject
(
'
IS_PRODUCTION_MODE
'
)
public
isProductionMode
,
private
tcs
:
TestControllerService
,
@
Inject
(
'
SERVER_URL
'
)
serverUrl
:
string
,
http
:
HttpClient
protected
http
:
HttpClient
)
{
super
(
serverUrl
,
http
);
...
...
@@ -32,19 +43,20 @@ export class CommandService extends WebsocketBackendService<Command[]> implement
this
.
setUpGlobalCommandsForDebug
();
}
this
.
command$
=
this
.
commandReceived$
.
pipe
(
concatMap
(
item
=>
timer
(
300
).
pipe
(
ignoreElements
(),
startWith
(
item
))),
// min delay between items
mergeMap
((
command
:
Command
)
=>
{
console
.
log
(
'
try to execute
'
+
CommandService
.
commandToString
(
command
));
return
this
.
http
.
patch
(
`
${
this
.
serverUrl
}
test/
${
this
.
tcs
.
testId
}
/command/
${
command
.
id
}
/executed`
,
{})
.
pipe
(
map
(()
=>
command
));
})
);
this
.
subscribeCommands
();
this
.
subscribeTestStarted
();
}
public
command$
:
Subject
<
Command
>
=
new
Subject
<
Command
>
();
private
commandSubscription
:
Subscription
;
initialData
=
[];
pollingEndpoint
=
''
;
pollingInterval
=
20000
;
wsChannelName
=
'
commands
'
;
private
commandHistory
:
number
[]
=
[];
private
testStartedSubscription
:
Subscription
;
private
static
commandToString
(
command
:
Command
):
string
{
return
`[
${
command
.
id
}
]
${
command
.
keyword
}
`
+
command
.
arguments
.
join
(
'
'
);
}
...
...
@@ -86,74 +98,57 @@ export class CommandService extends WebsocketBackendService<Command[]> implement
}
}),
switchMap
(
commands
=>
of
(...
commands
))
).
subscribe
(
this
.
command$
);
).
subscribe
(
this
.
command
Received
$
);
}
// TODO move to testcontroller maybe
private
subscribeCommands
()
{
this
.
commandSubscription
=
this
.
command$
.
pipe
(
concatMap
(
item
=>
timer
(
300
).
pipe
(
ignoreElements
(),
startWith
(
item
))),
// min delay between items
mergeMap
((
command
:
Command
)
=>
{
console
.
log
(
'
try to execute
'
+
CommandService
.
commandToString
(
command
));
return
this
.
http
.
patch
(
`
${
this
.
serverUrl
}
test/
${
this
.
tcs
.
testId
}
/command/
${
command
.
id
}
/executed`
,
{})
.
pipe
(
map
(()
=>
command
));
})
)
.
subscribe
((
command
:
Command
)
=>
{
this
.
executeCommand
(
command
);
this
.
commandSubscription
=
this
.
commandReceived$
.
subscribe
(
(
command
:
Command
)
=>
{
console
.
log
(
Date
.
now
()
+
'
---- execute command:
'
+
CommandService
.
commandToString
(
command
));
switch
(
command
.
keyword
)
{
case
'
pause
'
:
this
.
tcs
.
testStatus$
.
next
(
TestStatus
.
PAUSED
);
break
;
case
'
resume
'
:
this
.
tcs
.
testStatus$
.
next
(
TestStatus
.
RUNNING
);
break
;
case
'
terminate
'
:
this
.
tcs
.
terminateTest
();
break
;
case
'
goto
'
:
this
.
tcs
.
setUnitNavigationRequest
(
command
.
arguments
[
0
]);
break
;
case
'
debug
'
:
this
.
tcs
.
debugPane
=
command
.
arguments
[
0
]
!==
'
off
'
;
break
;
default
:
console
.
warn
(
`Unknown command: `
+
CommandService
.
commandToString
(
command
));
}
},
error
=>
console
.
warn
(
'
error for command
'
,
error
));
}
private
executeCommand
(
command
:
Command
)
{
console
.
log
(
Date
.
now
()
+
'
---- execute command:
'
+
CommandService
.
commandToString
(
command
));
if
(
this
.
commandHistory
.
indexOf
(
command
.
id
)
>=
0
)
{
console
.
warn
(
'
command already executed
'
+
CommandService
.
commandToString
(
command
));
}
this
.
commandHistory
.
push
(
command
.
id
);
switch
(
command
.
keyword
)
{
case
'
pause
'
:
this
.
tcs
.
testStatus$
.
next
(
TestStatus
.
PAUSED
);
break
;
case
'
resume
'
:
this
.
tcs
.
testStatus$
.
next
(
TestStatus
.
RUNNING
);
break
;
case
'
terminate
'
:
this
.
tcs
.
terminateTest
();
break
;
case
'
goto
'
:
this
.
tcs
.
setUnitNavigationRequest
(
command
.
arguments
[
0
]);
break
;
case
'
debug
'
:
this
.
tcs
.
debugPane
=
command
.
arguments
[
0
]
!==
'
off
'
;
break
;
default
:
console
.
warn
(
`Unknown command: `
+
CommandService
.
commandToString
(
command
));
}
}
private
setUpGlobalCommandsForDebug
()
{
window
[
'
tc
'
]
=
{};
commandKeywords
.
forEach
((
keyword
:
string
)
=>
{
const
randomNumber
=
Math
.
round
(
Math
.
random
()
*
-
10000000
);
window
[
'
tc
'
][
keyword
]
=
(
args
)
=>
{
this
.
commandFromTerminal
(
keyword
,
args
,
randomNumber
);
};
window
[
'
tc
'
][
keyword
]
=
(
args
)
=>
{
this
.
commandFromTerminal
(
keyword
,
args
);
};
});
}
private
commandFromTerminal
(
keyword
:
string
,
args
:
string
[]
,
id
:
number
):
void
{
private
commandFromTerminal
(
keyword
:
string
,
args
:
string
[]):
void
{
if
(
this
.
isProductionMode
)
{
return
;
}
args
=
(
typeof
args
===
'
undefined
'
)
?
[]
:
args
;
const
id
=
Math
.
round
(
Math
.
random
()
*
-
10000000
);
const
command
=
{
keyword
,
arguments
:
args
,
id
,
timestamp
:
Date
.
now
()};
if
(
!
isKnownCommand
(
keyword
))
{
console
.
warn
(
`Unknown command: `
+
CommandService
.
commandToString
(
command
));
return
;
}
this
.
executeCommand
(
command
);
this
.
commandReceived$
.
next
(
command
);
}
}
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