Skip to content

Commit

Permalink
Pre-rmisc fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Banker <[email protected]>
  • Loading branch information
loredous committed Jun 11, 2024
1 parent aa6e913 commit 7f21a19
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,4 @@ testem.log
Thumbs.db

src/python/state.pkl
src/python/statemachines.pkl
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
],
"cwd": "${workspaceFolder}/src/python/",
"console": "integratedTerminal",
"justMyCode": true
"justMyCode": true,
"env": {
"PYTHONPATH": "${workspaceFolder}/src/python/"
}
},
{
"name": "Python: FastAPI",
Expand Down
16 changes: 15 additions & 1 deletion src/python/controller/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from controller.statemachines import TestStateMachine
from controller.state import ControllerState, ControllerStateFactory
from shared.models.objects import Test
import warnings
import pickle

class ActiveStateMachines:
_active_state_machines: Dict[UUID, TestStateMachine] = {}
Expand All @@ -28,6 +28,18 @@ def remove_state_machine(self, test_id: UUID) -> None:
self.logger.debug(f"Removing state machine for test {test_id}")
self._active_state_machines.pop(test_id, None)

def persist_to_file(self, filename: str):
with open(filename, 'wb') as f:
pickle.dump(self, f)

def load_from_file(self, filename: str):
try:
with open(filename, "rb") as f:
state = pickle.load(f)
self.__dict__.update(state.__dict__)
except:
pass

async def cycle_state_machines(self) -> None:
to_remove = []
for test_id, state_machine in self._active_state_machines.items():
Expand All @@ -48,6 +60,7 @@ async def cycle_state_machines(self) -> None:
self.remove_state_machine(test_id)
except Exception as ex:
self.logger.exception(f"Error removing state machine for test {test_id}: {ex}")
self.persist_to_file('statemachines.pkl')


class ActiveStateMachinesFactory:
Expand All @@ -57,6 +70,7 @@ class ActiveStateMachinesFactory:
def get_active_state_machines(cls) -> ActiveStateMachines:
if not cls._active_state_machines:
cls._active_state_machines = ActiveStateMachines()
cls._active_state_machines.load_from_file('statemachines.pkl')
return cls._active_state_machines

ActiveStateMachinesDependency = Annotated[ActiveStateMachines, Depends(ActiveStateMachinesFactory.get_active_state_machines)]
Expand Down
1 change: 1 addition & 0 deletions src/ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<a clrVerticalNavLink routerLink="/manage/knocks" routerLinkActive="active">Knocks</a>
<a clrVerticalNavLink routerLink="/manage/results" routerLinkActive="active">Results</a>
<a clrVerticalNavLink routerLink="/manage/responses" routerLinkActive="active">Responses</a>
<a clrVerticalNavLink routerLink="/manage/response_expectations" routerLinkActive="active">Response Expectations</a>
<a clrVerticalNavLink routerLink="/manage/runners" routerLinkActive="active">Runners</a>
</clr-vertical-nav-group-children>
</clr-vertical-nav-group>
Expand Down
14 changes: 13 additions & 1 deletion src/ui/src/app/management/management.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Injector, OnInit, Type, ViewChild } from '@angular/core';
import { ICrudApiService, KnockAPIService, KnockerAPIService, MonitorAPIService, ResponseAPIService, ResultAPIService, RunnerAPIService, TestConfigurationAPIService, TestSuiteAPIService } from '../../tommyknocker-api.service';
import { ICrudApiService, KnockAPIService, KnockerAPIService, MonitorAPIService, ResponseAPIService, ResponseExpectationAPIService, ResultAPIService, RunnerAPIService, TestConfigurationAPIService, TestSuiteAPIService } from '../../tommyknocker-api.service';
import { NgFor, NgIf, NgSwitch, NgSwitchCase, NgSwitchDefault } from '@angular/common';
import { ClarityModule } from "@clr/angular";
import { FormsModule } from '@angular/forms';
Expand Down Expand Up @@ -139,6 +139,18 @@ const management_types: {[id: string]: IManagementType} = {
],
service: TestSuiteAPIService,
empty_item: { id: '', configuration_id: '' }
},
response_expectations: {
name: 'Response Expectation',
description: 'Response expectations dictate if a response is expected or not, and the timeout allowed for that response to occur.',
columns: [
{ name: 'id', title: 'ID', input_type: InputType.Input, copyable: true},
{ name: 'response_id', title: "Response", input_type: InputType.Lookup, lookup_interface: ResponseAPIService, createable: true, updateable: true},
{ name: 'expected', title: "Expected", input_type: InputType.Input, createable: true, updateable: true},
{ name: 'timeout', title: "Timeout", input_type: InputType.Input, createable: true, updateable: true}
],
service: ResponseExpectationAPIService,
empty_item: {id: '', response_id: '', expected: true, timeout: 60}
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/ui/src/tommyknocker-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export class ResponseAPIService<Response> extends BaseAPIService<Response> {
@Injectable({
providedIn: 'root'
})
export class ResponseExpectationAPIService<ResponseExpectation> extends BaseAPIService<ResponseExpectation> {
override api_path = '/response-expectations'
}
@Injectable({
providedIn: 'root'
})
export class KnockAPIService<Knock> extends BaseAPIService<Knock> {
override api_path = '/knocks';
}
Expand Down

0 comments on commit 7f21a19

Please sign in to comment.