Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
import { spawn } from 'child_process';
import * as assert from 'assert';
import * as path from 'path';
 
describe('Standalone Process Tests', () => {
  type ProcessResult = {
    code: number | null;
    signal: NodeJS.Signals | null;
    stdout: string;
    stderr: string;
  };
 
  // Helper function to run test script in a separate process
  const runTest = async (args: string[] = []): Promise<ProcessResult> =>
    new Promise((resolve, reject) => {
      // Use the compiled main.js file from the lib directory
      const testFile = path.join(__dirname, './main.js');
 
      const child = spawn('node', [testFile, ...args], { stdio: 'pipe' });
 
      let stdout = '';
      let stderr = '';
 
      child.stdout.on('data', (data) => (stdout += data.toString()));
      child.stderr.on('data', (data) => (stderr += data.toString()));
 
      child.on('close', (code, signal) => {
        resolve({ code, signal, stdout, stderr });
      });
 
      child.on('error', reject);
    });
 
  // Helper function to verify that the child was not terminated by a signal
  const assertNormalExit = (result: ProcessResult) => {
    assert.strictEqual(result.signal, null, `Child terminated by signal ${result.signal}.\n${result.stderr}`);
    assert.strictEqual(result.code, 0, result.stderr);
  };
 
  // Helper function to check basic success criteria
  const assertSuccess = (result: ProcessResult) => {
    assertNormalExit(result);
    assert.ok(result.stdout.includes('SUCCESS: Inference completed'));
    assert.ok(!result.stderr.includes('mutex lock failed'));
  };
 
  // Helper function to check that no mutex crashes occurred
  const assertNoMutexErrors = (stderr: string) => {
    assert.ok(!stderr.includes('mutex lock failed'));
    assert.ok(!stderr.includes('std::__1::system_error'));
  };
 
  it('should handle normal process exit', async () => {
    const result = await runTest([]);
    assertSuccess(result);
  });
 
  it('should handle process.exit() call', async () => {
    const result = await runTest(['--process-exit']);
    assertSuccess(result);
  });
 
  it('should handle uncaught exceptions', async () => {
    const result = await runTest(['--throw-exception']);
 
    assert.strictEqual(result.signal, null, `Child terminated by signal ${result.signal}.\n${result.stderr}`);
    assert.notStrictEqual(result.code, 0);
    assert.ok(result.stdout.includes('SUCCESS: Inference completed'));
    assert.ok(result.stderr.includes('Test exception'));
    assertNoMutexErrors(result.stderr);
  });
 
  it('should handle multiple process exits consistently', async () => {
    for (let i = 0; i < 3; i++) {
      const result = await runTest(['--process-exit']);
      assertSuccess(result);
    }
  });
 
  it('should handle session.release() before normal exit', async () => {
    const result = await runTest(['--release']);
    assertSuccess(result);
    assert.ok(result.stdout.includes('Session released'));
  });
 
  it('should handle session.release() before process.exit()', async () => {
    const result = await runTest(['--release', '--process-exit']);
    assertSuccess(result);
    assert.ok(result.stdout.includes('Session released'));
  });
 
  it('should handle no session.release() before process.exit()', async () => {
    const result = await runTest(['--process-exit']);
    assertSuccess(result);
    assert.ok(result.stdout.includes('Session NOT released'));
  });
 
  it('should allow repeated native ORT initialization', async () => {
    const result = await runTest(['--initialize-twice']);
    assertNormalExit(result);
    assert.ok(result.stdout.includes('SUCCESS: ORT initialized twice'));
  });
});