Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Aug 5, 2024
1 parent b8ba97b commit 67dfadf
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import CopyZone from 'widgets/CopyZone'
import { HIDE_BALANCE } from 'utils/const'
import TransactionType from 'components/TransactionType'
import { getLockedBalance } from 'services/remote/cellManage'
import { getFirstSyncInfo, setCkbNodeDataPath, startSync } from 'services/remote'
import { getFirstSyncInfo, setCkbNodeDataPath, startSync, testLongTimeTransaction } from 'services/remote'
import FirstSync from 'widgets/Icons/FirstSync.png'
import DataPathDialog from 'widgets/DataPathDialog'
import styles from './overview.module.scss'
Expand Down Expand Up @@ -167,6 +167,7 @@ const Overview = () => {
return (
<PageContainer head={t('navbar.overview')} notice={pageNotice} isHomePage>
<div className={styles.topContainer}>
<Button onClick={() => testLongTimeTransaction()}>Test Long Time Trasaction</Button>

Check warning on line 170 in packages/neuron-ui/src/components/Overview/index.tsx

View workflow job for this annotation

GitHub Actions / Check spell

"Trasaction" should be "Transaction".
<div className={styles.mid}>
<div className={styles.balance}>
<span className={styles.balanceTitle}>
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/services/remote/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const getFirstSyncInfo = remoteApi<void, { isFirstSync: boolean; needSize
'get-first-sync-info'
)
export const startSync = remoteApi<void, void>('start-sync')
export const testLongTimeTransaction = remoteApi<void, void>('long-time-hang')

export type VerifyExternalCkbNodeRes =
| {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/services/remote/remoteApiWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type Action =
| 'update-live-cell-local-info'
| 'get-locked-balance'
| 'update-live-cells-lock-status'
| 'long-time-hang'

export const remoteApi =
<P = any, R = any>(action: Action) =>
Expand Down
15 changes: 15 additions & 0 deletions packages/neuron-wallet/src/block-sync-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,18 @@ export async function changeMultisigSyncStatus(status: boolean) {
isSyncMultisigWithLight = status
await resetSyncTask(true)
}

export function longtimeTransaction() {
const msg: Required<WorkerMessage<undefined>> = {
type: 'call',
channel: 'longTimeHang',
id: requestId++,
message: undefined,
}
child?.send(msg, err => {
if (err) {
logger.error(`Sync:\tlongtimeTransaction failed: ${msg}`)
}
})
return true
}
8 changes: 7 additions & 1 deletion packages/neuron-wallet/src/block-sync-renderer/task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type QueryOptions } from '@ckb-lumos/base'
import initConnection from '../database/chain/ormconfig'
import { register as registerTxStatusListener } from './tx-status-listener'
import { longtimeTransaction, register as registerTxStatusListener } from './tx-status-listener'
import SyncQueue from './sync/queue'
import logger from '../utils/logger'
import { ShouldInChildProcess } from '../exceptions'
Expand All @@ -21,6 +21,7 @@ export interface WorkerMessage<T = any> {
| 'address-created'
| 'indexer-error'
| 'check-and-save-wallet-address'
| 'longTimeHang'
message: T
}

Expand Down Expand Up @@ -92,6 +93,11 @@ export const listener = async ({ type, id, channel, message }: WorkerMessage) =>
}
break
}

case 'longTimeHang': {
longtimeTransaction()
break
}
default: {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logger from '../utils/logger'
import { getConnection } from '../database/chain/connection'
import { interval } from 'rxjs'
import TxStatus from '../models/chain/tx-status'
import { scheduler } from 'timers/promises'

type TransactionDetail = {
hash: string
Expand Down Expand Up @@ -114,3 +115,13 @@ export const register = () => {
}
})
}

export const longtimeTransaction = () => {
return getConnection().manager.transaction(async manager => {
logger.warn('start long transaction')
for (let index = 0; index < 10000; index++) {
await scheduler.wait(1_000)
await manager.query(`INSERT INTO "test" ("id") VALUES ('${index}');`)
}
})
}
9 changes: 8 additions & 1 deletion packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import startMonitor, { stopMonitor } from '../services/monitor'
import { migrateCkbData } from '../services/ckb-runner'
import NodeService from '../services/node'
import SyncProgressService from '../services/sync-progress'
import { changeMultisigSyncStatus, resetSyncTaskQueue } from '../block-sync-renderer'
import { changeMultisigSyncStatus, longtimeTransaction, resetSyncTaskQueue } from '../block-sync-renderer'
import DataUpdateSubject from '../models/subjects/data-update'
import CellManagement from './cell-management'
import { UpdateCellLocalInfo } from '../database/chain/entities/cell-local-info'
Expand Down Expand Up @@ -995,6 +995,13 @@ export default class ApiController {
status: ResponseCode.Success,
}
})

handle('long-time-hang', async () => {
return {
result: longtimeTransaction(),
status: ResponseCode.Success,
}
})
}

// Register handler, warp and serialize API response
Expand Down

1 comment on commit 67dfadf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 10244057250

Please sign in to comment.