Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 124 additions & 7 deletions __mocks__/dh-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ class DeephavenObject {
callbacks[i](event);
}
}

nextEvent(name, timeout) {
let cleanup;
return new Promise((resolve, reject) => {
cleanup = this.addEventListener(name, detail => {
resolve(detail);
cleanup();
});
});
}

hasListeners(name) {
return (this._listeners[name]?.length ?? 0) > 0;
}
}

class Sort {
Expand Down Expand Up @@ -615,6 +629,11 @@ class Table extends DeephavenObject {
size = ROW_COUNT,
suppressFilter = false,
customColumns = [],
description = 'Mock Table',
layoutHints = null,
hasInputTable = false,
pluginName = null,
totalsTableConfig = {},
} = {}) {
super({ sort, filter, columns, size });

Expand All @@ -623,6 +642,7 @@ class Table extends DeephavenObject {
this.columns = columns;
this.customColumns = customColumns;
this.size = size;
this.totalSize = size;
this.suppressFilter = suppressFilter;

this.startRow = 0;
Expand All @@ -631,6 +651,11 @@ class Table extends DeephavenObject {
this.pendingViewportUpdate = false;
this.isClosed = false;
this.isUncoalesced = false;
this.description = description;
this.layoutHints = layoutHints;
this.hasInputTable = hasInputTable;
this.pluginName = pluginName;
this.totalsTableConfig = totalsTableConfig;
}

close() {}
Expand Down Expand Up @@ -665,7 +690,7 @@ class Table extends DeephavenObject {
const { startRow, endRow, viewportColumns, size, filter } = this;

if (startRow == null || endRow == null || viewportColumns == null) {
return null;
throw new Error('Viewport not set');
}

let rows = [];
Expand All @@ -686,13 +711,17 @@ class Table extends DeephavenObject {
return viewportData;
}

findColumn(name) {
const column = this.columns.find(col => col.name === name);
if (column === undefined) {
throw new Error(`Column ${name} not found`);
}
return column;
}

findColumns(names) {
return names.map(name => {
const column = this.columns.find(col => col.name === name);
if (column === undefined) {
throw new Error(`Column ${name} not found`);
}
return column;
return this.findColumn(name);
});
}

Expand Down Expand Up @@ -744,6 +773,10 @@ class Table extends DeephavenObject {
});
}

getGrandTotalsTable() {
return this.getTotalsTable();
}

selectDistinct() {
return new Promise((resolve, reject) => {
const table = makeDummyTable();
Expand All @@ -758,10 +791,46 @@ class Table extends DeephavenObject {
});
}

reverse() {
return this.copy();
}

rollup() {
return this.copy();
}

treeTable() {
return this.copy();
}

inputTable() {
return Promise.resolve(new InputTable());
}

freeze() {
return this.copy();
}

snapshot() {
return this.copy();
}

join() {
return this.copy();
}

byExternal() {
return this.copy();
}

seekRow() {
return Promise.resolve(-1);
}

getColumnStatistics() {
return Promise.reject(new Error('Column statistics not implemented'));
}

subscribe(columns, updateInterval = UPDATE_INTERVAL) {
return new TableSubscription({
table: this,
Expand All @@ -783,6 +852,8 @@ Table.EVENT_UPDATED = 'updated';
Table.EVENT_CONNECT = 'connect';
Table.EVENT_DISCONNECT = 'disconnect';
Table.EVENT_RECONNECT = 'reconnect';
Table.EVENT_RECONNECTFAILED = 'reconnectfailed';
Table.SIZE_UNCOALESCED = 'sizeuncoalesced';

class TableViewportSubscription extends DeephavenObject {
constructor({ table = makeDummyTable() } = {}) {
Expand Down Expand Up @@ -1277,9 +1348,34 @@ class IdeSession extends DeephavenObject {
this.language = language;
this.tables = [];
this.widgets = [];
this.logMessageCallbacks = [];
this.subscribeCallbacks = [];
}

onLogMessage(callback) {
this.logMessageCallbacks.push(callback);
return () => {
this.logMessageCallbacks = this.logMessageCallbacks.filter(
cb => cb !== callback
);
};
}

onLogMessage(callback) {}
subscribeToFieldUpdates(callback) {
this.subscribeCallbacks.push(callback);
return () => {
this.subscribeCallbacks = this.subscribeCallbacks.filter(
cb => cb !== callback
);
};
}

notifySubscribeCallbacks(changes) {
const callbacks = [...this.subscribeCallbacks];
callbacks.forEach(cb => {
cb(changes);
});
}

close() {}
/**
Expand Down Expand Up @@ -1377,6 +1473,8 @@ class IdeSession extends DeephavenObject {
}

timer = setTimeout(() => {
this.notifySubscribeCallbacks(tableChanges);
this.notifySubscribeCallbacks(widgetChanges);
resolve(result);
}, delay);
});
Expand Down Expand Up @@ -1416,6 +1514,23 @@ class IdeSession extends DeephavenObject {
});
}

getTreeTable(name) {
// We're just going to use a regular table for TreeTable
// Actual impl is different, but should be fine for mock
this.getTable(name);
}

getObject(variableDefinition) {
switch (variableDefinition.type) {
case dh.VariableType.FIGURE:
return this.getFigure(variableDefinition.title);
case dh.VariableType.TreeTable:
return this.getTreeTable(variableDefinition.title);
default:
return this.getTable(variableDefinition.title);
}
}

openDocument() {}
changeDocument() {}
getCompletionItems() {
Expand Down Expand Up @@ -1867,6 +1982,8 @@ const dh = {
TotalsTableConfig: TotalsTableConfig,
TableViewportSubscription,
TableSubscription,
// TreeTable and Table are different in actual implementation, but should be okay for the mock
TreeTable: Table,
Column: Column,
RangeSet,
Row: Row,
Expand Down
7 changes: 7 additions & 0 deletions packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ function AppInit(props: AppInitProps) {
setError(`Server shutdown: ${detail ?? 'Unknown reason'}`);
setDisconnectError(null);
});
connection.addEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
event => {
log.warn('Reconnect authentication failed');
setError('Reconnect authentication failed');
Comment thread
mofojed marked this conversation as resolved.
Outdated
}
);

const sessionWrapper = await loadSessionWrapper(connection);
const name = 'user';
Expand Down
53 changes: 30 additions & 23 deletions packages/console/src/HeapUsage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { useEffect, useState, ReactElement, useRef } from 'react';
import classNames from 'classnames';
import { Tooltip } from '@deephaven/components';
import { QueryConnectable } from '@deephaven/jsapi-shim';
import React, { useEffect, useState, ReactElement, useRef } from 'react';
import { Plot, ChartTheme } from '@deephaven/chart';
import Log from '@deephaven/log';
import './HeapUsage.scss';
import classNames from 'classnames';

const log = Log.module('HeapUsage');

interface HeapUsageProps {
connection: QueryConnectable;
Expand Down Expand Up @@ -38,28 +41,32 @@ function HeapUsage({
useEffect(
function setUsageUpdateInterval() {
const fetchAndUpdate = async () => {
const newUsage = await connection.getWorkerHeapInfo();
setMemoryUsage(newUsage);

if (bgMonitoring || isOpen) {
const currentUsage =
(newUsage.totalHeapSize - newUsage.freeMemory) /
newUsage.maximumHeapSize;
const currentTime = Date.now();

const { timestamps, usages } = historyUsage.current;
while (
timestamps.length !== 0 &&
currentTime - timestamps[0] > monitorDuration * 1.5
) {
timestamps.shift();
usages.shift();
try {
const newUsage = await connection.getWorkerHeapInfo();
setMemoryUsage(newUsage);

if (bgMonitoring || isOpen) {
const currentUsage =
(newUsage.totalHeapSize - newUsage.freeMemory) /
newUsage.maximumHeapSize;
const currentTime = Date.now();

const { timestamps, usages } = historyUsage.current;
while (
timestamps.length !== 0 &&
currentTime - timestamps[0] > monitorDuration * 1.5
) {
timestamps.shift();
usages.shift();
}

timestamps.push(currentTime);
usages.push(currentUsage);
} else {
historyUsage.current = { timestamps: [], usages: [] };
}

timestamps.push(currentTime);
usages.push(currentUsage);
} else {
historyUsage.current = { timestamps: [], usages: [] };
} catch (e) {
log.warn('Unable to get heap usage', e);
}
};
fetchAndUpdate();
Expand Down
11 changes: 2 additions & 9 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ jest.mock('@deephaven/console', () => ({
default: props => mockConsole(props),
}));

function makeSession(): IdeSession {
return ({
addEventListener: jest.fn(),
subscribeToFieldUpdates: jest.fn(() => () => null),
removeEventListener: jest.fn(),
getTable: jest.fn(),
getObject: jest.fn(),
runCode: jest.fn(),
} as unknown) as IdeSession;
function makeSession(language = 'TEST_LANG'): IdeSession {
return (new dh.IdeSession(language) as unknown) as IdeSession;
}

function makeConnection({
Expand Down
8 changes: 7 additions & 1 deletion packages/iris-grid/src/sidebar/TableCsvExporter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const TABLE = IrisGridTestUtils.makeTable({
size: 100,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const BAD_TABLE = new (dh as any).Table({});
const BAD_TABLE = IrisGridTestUtils.makeTable({
columns: COLUMN_NAMES.map(name => IrisGridTestUtils.makeColumn(name)),
size: 100,
});
BAD_TABLE.freeze = jest.fn(() =>
Promise.reject(new Error('Test invalid error'))
);

function makeTableCsvExporterWrapper({
name = 'TEST',
Expand Down
7 changes: 6 additions & 1 deletion packages/jsapi-types/src/dh.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,12 @@ export interface StorageService {
createDirectory(path: string): Promise<void>;
}

export interface CoreClientContructor {
export interface CoreClientContructor extends Evented {
EVENT_CONNECT: string;
EVENT_DISCONNECT: string;
EVENT_RECONNECT: string;
EVENT_RECONNECT_AUTH_FAILED: string;
EVENT_REFRESH_TOKEN_UPDATED: string;
LOGIN_TYPE_ANONYMOUS: string;
new (serverUrl: string): CoreClient;
}
Expand Down