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 &
cd ..
scripts/e2e.sh 16
scripts/e2e.sh 8
- name: Cleanup
if: always()

View file

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

View file

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

View file

@ -16,41 +16,40 @@ export class ServerConfig {
public constructor(private readonly syncService: SyncService) {}
public async initialize(): Promise<void> {
this.response = this.syncService.ping();
this.config = await this.response;
if (this.config.supportedApiVersion !== SUPPORTED_API_VERSION) {
private static validateConfig(config: ServerConfigData): void {
if (config.supportedApiVersion !== SUPPORTED_API_VERSION) {
const shouldUpgradeClient =
this.config.supportedApiVersion > SUPPORTED_API_VERSION;
config.supportedApiVersion > SUPPORTED_API_VERSION;
throw new ServerVersionMismatchError(
`Unsupported API version: ${this.config.supportedApiVersion}. Consider upgrading the ${
`Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${
shouldUpgradeClient ? "client" : "sync-server"
} to ensure compatibility.`
} to ensure compatibility`
);
}
if (!this.config.isAuthenticated) {
if (!config.isAuthenticated) {
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<{
isSuccessful: boolean;
message: string;
}> {
try {
let { response } = this;
if (!response && !forceUpdate) {
throw new Error("ServerConfig not initialized");
} else if (forceUpdate) {
if (!response || forceUpdate) {
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;
if (result.isAuthenticated) {
@ -72,11 +71,14 @@ export class ServerConfig {
}
}
public getConfig(): ServerConfigData {
public async getConfig(): Promise<ServerConfigData> {
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;
}

View file

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

View file

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