Files
yoga/java/tests/com/facebook/yoga/YogaLoggerTest.java
Amir Shalem d697bbe0a5 Switch to YogaConfigFactory.create
Summary: Switch to `YogaNodeFactory.create()` instead of using `YogaNode.create()`

Reviewed By: SidharthGuglani

Differential Revision: D17266408

fbshipit-source-id: 69e1e59c7345d16eb174af97c2e231666a02354b
2019-09-17 07:15:23 -07:00

41 lines
1.1 KiB
Java

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
package com.facebook.yoga;
import org.junit.Test;
import java.lang.ref.WeakReference;
import static org.junit.Assert.fail;
public class YogaLoggerTest {
@Test
public void testLoggerLeak() throws Exception {
final YogaConfig config = YogaConfigFactory.create();
YogaLogger logger = new YogaLogger() {
@Override
public void log(YogaNode yogaNode, YogaLogLevel level, String message) {
}
};
config.setLogger(logger);
config.setLogger(null);
WeakReference<Object> ref = new WeakReference<Object>(logger);
// noinspection UnusedAssignment
logger = null;
// try and free for the next 5 seconds, usually it works after the
// first GC attempt.
for (int i=0; i < 50; i++) {
System.gc();
if (ref.get() == null) {
// free successfully
return;
}
Thread.sleep(100);
}
fail("YogaLogger leaked");
}
}