Fix memory leaks in integration tests

This commit is contained in:
jaina heartles 2022-12-18 06:21:04 -08:00
parent 64bbb7dae9
commit 613215efec
3 changed files with 21 additions and 6 deletions

View file

@ -39,7 +39,9 @@ fn connectAndLogin(
var conn = try api_source.connectUnauthorized(host, alloc);
defer conn.close();
return try util.deepClone(alloc, try conn.login(username, password));
const result = try conn.login(username, password);
defer util.deepFree(conn.allocator, result);
return try util.deepClone(alloc, result);
}
test "login as root" {
@ -54,6 +56,7 @@ test "login as root" {
var conn = try src.connectToken(admin_host, login.token, alloc);
defer conn.close();
const auth = try conn.verifyAuthorization();
defer util.deepFree(conn.allocator, auth);
try std.testing.expectEqual(login.user_id, auth.id);
try std.testing.expectEqualStrings(root_user, auth.username);
@ -74,6 +77,7 @@ test "create community" {
const host = "fedi.example.com";
const community = try conn.createCommunity("https://" ++ host, null);
defer util.deepFree(alloc, community);
try std.testing.expectEqual(api.Community.Scheme.https, community.scheme);
try std.testing.expectEqual(api.Community.Kind.local, community.kind);
@ -83,7 +87,10 @@ test "create community" {
}
test "create community and transfer to new owner" {
const alloc = std.testing.allocator;
//const alloc = std.testing.allocator;
var gpa = std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = 16 }){};
defer _ = gpa.deinit();
const alloc = gpa.allocator();
var db = try makeDb(alloc);
defer db.deinit();
var src = try ApiSource.init(&db);
@ -97,7 +104,9 @@ test "create community and transfer to new owner" {
defer conn.close();
const community = try conn.createCommunity("https://" ++ host, null);
defer util.deepFree(conn.allocator, community);
const invite = try conn.createInvite(.{ .to_community = community.id, .kind = .community_owner });
defer util.deepFree(conn.allocator, invite);
break :blk try util.deepClone(alloc, invite);
};
defer util.deepFree(alloc, invite);
@ -108,7 +117,7 @@ test "create community and transfer to new owner" {
var conn = try src.connectUnauthorized(host, alloc);
defer conn.close();
_ = try conn.register(username, password, .{ .invite_code = invite.code });
util.deepFree(conn.allocator, try conn.register(username, password, .{ .invite_code = invite.code }));
}
const login = try connectAndLogin(&src, host, username, password, alloc);
@ -118,6 +127,7 @@ test "create community and transfer to new owner" {
defer conn.close();
const auth = try conn.verifyAuthorization();
defer util.deepFree(conn.allocator, auth);
try std.testing.expectEqual(login.user_id, auth.id);
try std.testing.expectEqualStrings(username, auth.username);