Skip to content

Commit

Permalink
Moved "Logging" test out of "SessionTest" because the importApp funct…
Browse files Browse the repository at this point in the history
…ion has gone away
  • Loading branch information
kraenhansen committed Feb 19, 2024
1 parent 5fbbcaf commit ff58f60
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
1 change: 1 addition & 0 deletions integration-tests/tests/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import "./tests/sync/dictionary";
import "./tests/sync/encryption";
import "./tests/sync/flexible";
import "./tests/sync/geospatial";
import "./tests/sync/logging";
import "./tests/sync/mixed";
import "./tests/sync/mongo-db-client";
import "./tests/sync/open-behavior";
Expand Down
48 changes: 48 additions & 0 deletions integration-tests/tests/src/tests/sync/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

import Realm from "realm";
import { importAppBefore } from "../../hooks";
import { buildAppConfig } from "../../utils/build-app-config";

describe("Logging", () => {
importAppBefore(buildAppConfig("with-pbs").anonAuth().flexibleSync());
afterEach(() => Realm.clearTestState());
// Skipped because reusing a single app across tests break this
it("can set custom logging function", async function (this: AppContext) {
const credentials = Realm.Credentials.anonymous();

const logLevelStr = "info"; // "all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"
const logLevelNum = 4; // == "info", see index.d.ts, logger.hpp for definitions

const promisedLog = new Promise((resolve) => {
Realm.App.Sync.setLogLevel(this.app, logLevelStr);
Realm.App.Sync.setLogger(this.app, (level, message) => {
if (level == logLevelNum && message.includes("Connection") && message.includes("Session")) {
// we should, at some point, receive a log message that looks like
// Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, client reset = false
resolve(true);
}
});
});

const user = await this.app.logIn(credentials);
await Realm.open({ sync: { user, flexible: true } });
await promisedLog;
});
});
33 changes: 0 additions & 33 deletions integration-tests/tests/src/tests/sync/sync-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,39 +344,6 @@ describe("SessionTest", () => {
});
});

describe("Logging", () => {
afterEach(() => Realm.clearTestState());
// Skipped because reusing a single app across tests break this
it.skip("can set custom logging function", async function (this: AppContext) {
// setting a custom logging function must be done immediately after instantiating an app

const { appId, baseUrl } = await importApp(buildAppConfig("with-pbs").anonAuth().partitionBasedSync().config);
const app = new Realm.App({ id: appId, baseUrl });

const partition = generatePartition();
const credentials = Realm.Credentials.anonymous();

const logLevelStr = "info"; // "all", "trace", "debug", "detail", "info", "warn", "error", "fatal", "off"
const logLevelNum = 4; // == "info", see index.d.ts, logger.hpp for definitions

const promisedLog = new Promise((resolve) => {
Realm.App.Sync.setLogLevel(app, logLevelStr);
Realm.App.Sync.setLogger(app, (level, message) => {
if (level == logLevelNum && message.includes("Connection") && message.includes("Session")) {
// we should, at some point, receive a log message that looks like
// Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, client reset = false
resolve(true);
}
});
});

const user = await app.logIn(credentials);
const config = getSyncConfiguration(user, partition);
await Realm.open(config);
await promisedLog;
});
});

describe("Connection", () => {
afterEach(() => Realm.clearTestState());
it("can add connectionNotification", async function (this: AppContext) {
Expand Down

0 comments on commit ff58f60

Please sign in to comment.