Try fixing E2E tests more

This commit is contained in:
Andras Schmelczer 2025-12-11 22:08:48 +00:00
parent 387e7afd58
commit f6dccc4492
6 changed files with 33 additions and 30 deletions

View file

@ -49,7 +49,7 @@ jobs:
cargo run config-e2e.yml --color never & cargo run config-e2e.yml --color never &
cd .. cd ..
scripts/e2e.sh 16 scripts/e2e.sh 8
- name: Cleanup - name: Cleanup
if: always() if: always()

View file

@ -12,7 +12,7 @@ import type { TextWithCursors } from "reconcile-text";
import type { ServerConfig, ServerConfigData } from "../services/server-config"; import type { ServerConfig, ServerConfigData } from "../services/server-config";
class MockServerConfig implements Pick<ServerConfig, "getConfig"> { class MockServerConfig implements Pick<ServerConfig, "getConfig"> {
public getConfig(): ServerConfigData { public async getConfig(): Promise<ServerConfigData> {
return { return {
mergeableFileExtensions: ["md", "txt"], mergeableFileExtensions: ["md", "txt"],
supportedApiVersion: 1, supportedApiVersion: 1,

View file

@ -97,7 +97,7 @@ export class FileOperations {
if ( if (
!isFileTypeMergable( !isFileTypeMergable(
path, path,
this.serverConfig.getConfig().mergeableFileExtensions (await this.serverConfig.getConfig()).mergeableFileExtensions
) || ) ||
isBinary(expectedContent) || isBinary(expectedContent) ||
isBinary(newContent) isBinary(newContent)

View file

@ -16,41 +16,40 @@ export class ServerConfig {
public constructor(private readonly syncService: SyncService) {} public constructor(private readonly syncService: SyncService) {}
public async initialize(): Promise<void> { private static validateConfig(config: ServerConfigData): void {
this.response = this.syncService.ping(); if (config.supportedApiVersion !== SUPPORTED_API_VERSION) {
this.config = await this.response;
if (this.config.supportedApiVersion !== SUPPORTED_API_VERSION) {
const shouldUpgradeClient = const shouldUpgradeClient =
this.config.supportedApiVersion > SUPPORTED_API_VERSION; config.supportedApiVersion > SUPPORTED_API_VERSION;
throw new ServerVersionMismatchError( throw new ServerVersionMismatchError(
`Unsupported API version: ${this.config.supportedApiVersion}. Consider upgrading the ${ `Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${
shouldUpgradeClient ? "client" : "sync-server" shouldUpgradeClient ? "client" : "sync-server"
} to ensure compatibility.` } to ensure compatibility`
); );
} }
if (!this.config.isAuthenticated) { if (!config.isAuthenticated) {
throw new AuthenticationError( throw new AuthenticationError(
"Failed to authenticate with the sync-server." "Failed to authenticate with the sync-server"
); );
} }
} }
// warm the cache
public async initialize(): Promise<void> {
await this.getConfig();
}
public async checkConnection(forceUpdate = false): Promise<{ public async checkConnection(forceUpdate = false): Promise<{
isSuccessful: boolean; isSuccessful: boolean;
message: string; message: string;
}> { }> {
try { try {
let { response } = this; let { response } = this;
if (!response && !forceUpdate) { if (!response || forceUpdate) {
throw new Error("ServerConfig not initialized");
} else if (forceUpdate) {
response = this.response = this.syncService.ping(); response = this.response = this.syncService.ping();
} }
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion const result: PingResponse = await response; // it must be defined, otherwise we would have thrown above
const result: PingResponse = (await response)!; // it must be defined, otherwise we would have thrown above
this.config = result; this.config = result;
if (result.isAuthenticated) { if (result.isAuthenticated) {
@ -72,11 +71,14 @@ export class ServerConfig {
} }
} }
public getConfig(): ServerConfigData { public async getConfig(): Promise<ServerConfigData> {
if (!this.config) { if (!this.config) {
throw new Error("ServerConfig not initialized"); this.response ??= this.syncService.ping();
this.config = await this.response;
} }
ServerConfig.validateConfig(this.config);
return this.config; return this.config;
} }

View file

@ -108,7 +108,7 @@ export class UnrestrictedSyncer {
); );
this.database.addSeenUpdateId(response.vaultUpdateId); this.database.addSeenUpdateId(response.vaultUpdateId);
this.updateCache( await this.updateCache(
response.vaultUpdateId, response.vaultUpdateId,
contentBytes, contentBytes,
response.relativePath response.relativePath
@ -206,7 +206,8 @@ export class UnrestrictedSyncer {
!isBinary(contentBytes) && !isBinary(contentBytes) &&
isFileTypeMergable( isFileTypeMergable(
document.relativePath, document.relativePath,
this.serverConfig.getConfig().mergeableFileExtensions (await this.serverConfig.getConfig())
.mergeableFileExtensions
); );
const cachedVersion = this.contentCache.get( const cachedVersion = this.contentCache.get(
document.metadata.parentVersionId document.metadata.parentVersionId
@ -300,7 +301,7 @@ export class UnrestrictedSyncer {
contentBytes, contentBytes,
responseBytes responseBytes
); );
this.updateCache( await this.updateCache(
response.vaultUpdateId, response.vaultUpdateId,
responseBytes, responseBytes,
actualPath actualPath
@ -322,7 +323,7 @@ export class UnrestrictedSyncer {
}, },
document document
); );
this.updateCache( await this.updateCache(
response.vaultUpdateId, response.vaultUpdateId,
contentBytes, contentBytes,
actualPath actualPath
@ -451,7 +452,7 @@ export class UnrestrictedSyncer {
remoteVersion.relativePath, remoteVersion.relativePath,
contentBytes contentBytes
); );
this.updateCache( await this.updateCache(
remoteVersion.vaultUpdateId, remoteVersion.vaultUpdateId,
contentBytes, contentBytes,
remoteVersion.relativePath remoteVersion.relativePath
@ -547,15 +548,15 @@ export class UnrestrictedSyncer {
} }
} }
private updateCache( private async updateCache(
updateId: number, updateId: number,
contentBytes: Uint8Array, contentBytes: Uint8Array,
filePath: RelativePath filePath: RelativePath
): void { ): Promise<void> {
if ( if (
isFileTypeMergable( isFileTypeMergable(
filePath, filePath,
this.serverConfig.getConfig().mergeableFileExtensions (await this.serverConfig.getConfig()).mergeableFileExtensions
) && ) &&
!isBinary(contentBytes) !isBinary(contentBytes)
) { ) {

View file

@ -50,8 +50,8 @@ for i in $(seq 1 $process_count); do
pids+=($pid) pids+=($pid)
echo "Started process $i with PID: $pid" echo "Started process $i with PID: $pid"
# Read from pipe, prefix with PID, and write to log file # Read from pipe, prefix with PID
(sed "s/^/[PID $pid] /" < "$pipe" > "../logs/log_${i}.log"; rm "$pipe") & (sed "s/^/[PID $pid] /" < "$pipe" | tee "../logs/log_${i}.log"; rm "$pipe") &
done done
cd .. cd ..