forked from Kotlin/kotlinx.serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak caused by invalid KTypeWrapper's equals method (Kotli…
…n#2274) * Fix KTypeWrapper equality bug to avoid memory leak * Optimize imports of CachingTest.kt
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization | ||
|
||
import kotlinx.serialization.internal.* | ||
import kotlinx.serialization.modules.* | ||
import org.junit.Test | ||
import kotlin.reflect.* | ||
import kotlin.test.* | ||
|
||
class CachingTest { | ||
@Test | ||
fun testCache() { | ||
var factoryCalled = 0 | ||
|
||
val cache = createCache { | ||
factoryCalled += 1 | ||
it.serializerOrNull() | ||
} | ||
|
||
repeat(10) { | ||
cache.get(typeOf<String>().kclass()) | ||
} | ||
|
||
assertEquals(1, factoryCalled) | ||
} | ||
|
||
@Test | ||
fun testParameterizedCache() { | ||
var factoryCalled = 0 | ||
|
||
val cache = createParametrizedCache { clazz, types -> | ||
factoryCalled += 1 | ||
val serializers = EmptySerializersModule().serializersForParameters(types, true)!! | ||
clazz.parametrizedSerializerOrNull(types, serializers) | ||
} | ||
|
||
repeat(10) { | ||
cache.get(typeOf<Map<*, *>>().kclass(), listOf(typeOf<String>(), typeOf<String>())) | ||
} | ||
|
||
assertEquals(1, factoryCalled) | ||
} | ||
} |