Skip to content

Commit

Permalink
Merge pull request #921 from Green-Software-Foundation/time-sync
Browse files Browse the repository at this point in the history
Time sync
  • Loading branch information
narekhovhannisyan committed Aug 1, 2024
2 parents d7a8853 + 593c7af commit 485ca1a
Show file tree
Hide file tree
Showing 16 changed files with 406 additions and 122 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/dispatch-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run if-check on requested branch

on:
workflow_dispatch:

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Run integration tests
run: npm run if-check -- -d manifests/outputs
19 changes: 6 additions & 13 deletions manifests/examples/builtins/time-sync/success.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
name: time-sync
description: successful path
tags:
'time-sync':
start-time: '2023-12-12T00:00:00.000Z'
end-time: '2023-12-12T00:01:00.000Z'
interval: 5
allow-padding: true
initialize:
output:
- yaml
plugins:
'time-sync':
method: TimeSync
path: "builtin"
global-config:
start-time: '2023-12-12T00:00:00.000Z'
end-time: '2023-12-12T00:01:00.000Z'
interval: 5
allow-padding: true
plugins: {}
tree:
children:
child:
pipeline:
- time-sync
config:
inputs:
- timestamp: '2023-12-12T00:00:00.000Z'
Expand Down
132 changes: 131 additions & 1 deletion src/__tests__/if-run/lib/compute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,59 @@ describe('lib/compute: ', () => {
kind: 'execute',
},
});
const mockObservePlugin = () => ({
execute: () => [
{timestamp: '2024-09-02', duration: 40, 'cpu/utilization': 30},
{timestamp: '2024-09-03', duration: 60, 'cpu/utilization': 40},
],
metadata: {
kind: 'execute',
},
});
const mockObservePluginTimeSync = () => ({
execute: () => [
{
timestamp: '2023-12-12T00:00:00.000Z',
duration: 60,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:01:00.000Z',
duration: 60,
'cpu/utilization': 40,
},
],
metadata: {
kind: 'execute',
},
});
const mockTimeSync = () => ({
execute: () => [
{
timestamp: '2023-12-12T00:00:00.000Z',
duration: 30,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:00:30.000Z',
duration: 30,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:01:00.000Z',
duration: 30,
'cpu/utilization': 40,
},
{
timestamp: '2023-12-12T00:01:30.000Z',
duration: 30,
'cpu/utilization': 40,
},
],
metadata: {
kind: 'execute',
},
});
/**
* Compute params.
*/
Expand All @@ -35,7 +88,11 @@ describe('lib/compute: ', () => {
},
},
},
pluginStorage: pluginStorage().set('mock', mockExecutePlugin()),
pluginStorage: pluginStorage()
.set('mock', mockExecutePlugin())
.set('mock-observe', mockObservePlugin())
.set('mock-observe-time-sync', mockObservePluginTimeSync())
.set('time-sync', mockTimeSync()),
};

describe('compute(): ', () => {
Expand Down Expand Up @@ -221,4 +278,77 @@ describe('lib/compute: ', () => {
expect(response.children.mockChild.outputs).toEqual(expectedResult);
});
});

it('computes simple tree with observe plugin.', async () => {
const tree = {
children: {
mockChild: {
pipeline: {observe: ['mock-observe']},
},
},
};

const response = await compute(tree, paramsExecute);
const expectedResult = [
{timestamp: '2024-09-02', duration: 40, 'cpu/utilization': 30},
{timestamp: '2024-09-03', duration: 60, 'cpu/utilization': 40},
];

expect(response.children.mockChild.inputs).toEqual(expectedResult);
});

it('computes simple tree with time sync plugin.', async () => {
const tree = {
children: {
mockChild: {
pipeline: {observe: ['mock-observe-time-sync']},
},
},
};
const timeSync = {
'start-time': '2023-12-12T00:00:00.000Z',
'end-time': '2023-12-12T00:02:00.000Z',
interval: 5,
'allow-padding': true,
};

const response = await compute(tree, {...paramsExecute, timeSync});
const expectedInputs = [
{
timestamp: '2023-12-12T00:00:00.000Z',
duration: 60,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:01:00.000Z',
duration: 60,
'cpu/utilization': 40,
},
];
const expectedOutput = [
{
timestamp: '2023-12-12T00:00:00.000Z',
duration: 30,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:00:30.000Z',
duration: 30,
'cpu/utilization': 30,
},
{
timestamp: '2023-12-12T00:01:00.000Z',
duration: 30,
'cpu/utilization': 40,
},
{
timestamp: '2023-12-12T00:01:30.000Z',
duration: 30,
'cpu/utilization': 40,
},
];

expect(response.children.mockChild.inputs).toEqual(expectedInputs);
expect(response.children.mockChild.outputs).toEqual(expectedOutput);
});
});
Loading

0 comments on commit 485ca1a

Please sign in to comment.