|
| 1 | +import { describe, test, expect, afterAll, beforeAll } from 'bun:test'; |
| 2 | +import { |
| 3 | + CONFIG, |
| 4 | + docker, |
| 5 | + generateDockerComposeAndStartNetwork, |
| 6 | + getDevnetStatus, |
| 7 | + stopAndRemoveNetwork, |
| 8 | + waitForMinCutHeight, |
| 9 | +} from './devnet-utils'; |
| 10 | +import type { ContainerLogsOptions } from 'dockerode'; |
| 11 | + |
| 12 | +describe('e2e: check container logs during for errors, warnings, crashes etc', () => { |
| 13 | + beforeAll(async () => { |
| 14 | + await stopAndRemoveNetwork('kadena-dev'); |
| 15 | + await generateDockerComposeAndStartNetwork('kadena-dev'); |
| 16 | + }); |
| 17 | + afterAll(() => { |
| 18 | + if (CONFIG.CLEAN_AFTER) { |
| 19 | + // return stopAndRemoveNetwork('kadena-dev'); |
| 20 | + } |
| 21 | + }); |
| 22 | + |
| 23 | + const containerArray = [ |
| 24 | + 'miner-1-mining-client', |
| 25 | + 'miner-1-consensus', |
| 26 | + 'miner-1-evm-init-20', |
| 27 | + 'miner-1-evm-init-21', |
| 28 | + 'miner-1-evm-init-22', |
| 29 | + 'miner-1-evm-init-23', |
| 30 | + 'miner-1-evm-init-24', |
| 31 | + 'miner-1-evm-20', |
| 32 | + 'miner-1-evm-21', |
| 33 | + 'miner-1-evm-22', |
| 34 | + 'miner-1-evm-23', |
| 35 | + 'miner-1-evm-24', |
| 36 | + 'miner-2-mining-client', |
| 37 | + 'miner-2-consensus', |
| 38 | + 'miner-2-evm-init-20', |
| 39 | + 'miner-2-evm-init-21', |
| 40 | + 'miner-2-evm-init-22', |
| 41 | + 'miner-2-evm-init-23', |
| 42 | + 'miner-2-evm-init-24', |
| 43 | + 'miner-2-evm-20', |
| 44 | + 'miner-2-evm-21', |
| 45 | + 'miner-2-evm-22', |
| 46 | + 'miner-2-evm-23', |
| 47 | + 'miner-2-evm-24', |
| 48 | + 'bootnode-allocations', |
| 49 | + 'bootnode-consensus', |
| 50 | + 'bootnode-evm-init-20', |
| 51 | + 'bootnode-evm-init-21', |
| 52 | + 'bootnode-evm-init-22', |
| 53 | + 'bootnode-evm-init-23', |
| 54 | + 'bootnode-evm-init-24', |
| 55 | + 'bootnode-evm-20', |
| 56 | + 'bootnode-evm-21', |
| 57 | + 'bootnode-evm-22', |
| 58 | + 'bootnode-evm-23', |
| 59 | + 'bootnode-evm-24', |
| 60 | + 'appdev-frontend', |
| 61 | + 'appdev-evm-init-20', |
| 62 | + 'appdev-evm-init-24', |
| 63 | + 'appdev-evm-20', |
| 64 | + 'appdev-evm-24', |
| 65 | + 'appdev-consensus', |
| 66 | + ]; |
| 67 | + |
| 68 | + const filterErrorLines = |
| 69 | + (cleanFunction?: (container: string, lines: string[]) => string[]) => |
| 70 | + async (container: string): Promise<string[]> => { |
| 71 | + console.log('starting log check for', container); |
| 72 | + const c = await docker.getContainer(container.trim()); |
| 73 | + |
| 74 | + // Fetch logs |
| 75 | + const logBuffer = await c.logs({ |
| 76 | + follow: false, |
| 77 | + stdout: true, |
| 78 | + stderr: true, |
| 79 | + timestamps: true, |
| 80 | + }); |
| 81 | + |
| 82 | + // Convert buffer to string and split into lines |
| 83 | + const logText = logBuffer.toString('utf8'); |
| 84 | + const logLines = logText.split('\n'); |
| 85 | + const affectedLines: string[] = []; |
| 86 | + |
| 87 | + // Filter and display lines containing errors, warnings, or crashes |
| 88 | + logLines.forEach((line) => { |
| 89 | + if (/error|warning|crash|exception|failed/i.test(line)) { |
| 90 | + affectedLines.push(line); |
| 91 | + console.log(container, 'Issue detected:', line); |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + if (cleanFunction) { |
| 96 | + return cleanFunction(container, affectedLines); |
| 97 | + } |
| 98 | + |
| 99 | + return affectedLines; |
| 100 | + }; |
| 101 | + |
| 102 | + // the appdev-consensus container and the bootnode-consensus container have a some expected warnings |
| 103 | + // because no miners were started in those containers. so we can ignore those lines |
| 104 | + const cleanLines = (container: string, lines: string[]): string[] => { |
| 105 | + return lines.filter( |
| 106 | + (line) => |
| 107 | + !/EVM miner address is not set for ChainId/.test(line) && |
| 108 | + container !== 'appdev-consensus' && |
| 109 | + container !== 'bootnode-consensus' |
| 110 | + ); |
| 111 | + }; |
| 112 | + |
| 113 | + test('should show no errors on startup', async () => { |
| 114 | + const promises = containerArray.map(filterErrorLines(cleanLines)); |
| 115 | + const results = await Promise.all(promises); |
| 116 | + |
| 117 | + results.forEach((logsArray) => { |
| 118 | + expect(logsArray.length).toBe(0); |
| 119 | + }); |
| 120 | + }); |
| 121 | + test('should show no errors during block production', async () => { |
| 122 | + const devnetStatus = await getDevnetStatus(); |
| 123 | + await waitForMinCutHeight(devnetStatus.cutHeight + 98 * 1, { timeoutSeconds: 150 }); |
| 124 | + |
| 125 | + const promises = containerArray.map(filterErrorLines(cleanLines)); |
| 126 | + const results = await Promise.all(promises); |
| 127 | + |
| 128 | + results.forEach((logsArray) => { |
| 129 | + expect(logsArray.length).toBe(0); |
| 130 | + }); |
| 131 | + }); |
| 132 | +}); |
0 commit comments