Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nanosecond conversion on native #3386

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.apollographql.apollo3.mpp

import kotlinx.cinterop.convert
import kotlinx.cinterop.pointed
import platform.Foundation.NSThread
import platform.darwin.DISPATCH_TIME_NOW
import platform.darwin.dispatch_time
Expand All @@ -12,7 +11,7 @@ import kotlin.native.concurrent.isFrozen

actual fun currentTimeMillis(): Long {
val nanoseconds: Long = dispatch_time(DISPATCH_TIME_NOW, 0).convert()
return nanoseconds * 1_000_000L
return nanoseconds / 1_000_000L
}
actual fun currentThreadId(): String {
return pthread_self()?.rawValue.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ class MemoryCacheTest {
}

@Test
fun testExpiration() {
fun testExpiresImmediatly() {
val testRecord = createTestRecord("")
val lruCache = createCache(expireAfterMillis = 0)
lruCache.merge(testRecord, CacheHeaders.NONE)

assertNull(lruCache.loadRecord(testRecord.key, CacheHeaders.NONE))
}


@Test
fun testDualCacheSingleRecord() {
val secondaryCache = createCache()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package test

import com.apollographql.apollo3.cache.CacheHeaders
import com.apollographql.apollo3.cache.normalized.MemoryCache
import com.apollographql.apollo3.cache.normalized.Record
import com.apollographql.apollo3.testing.runWithMainLoop
import kotlinx.coroutines.delay
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class MemoryCacheTest {
@Test
fun testDoesNotExpireBeforeMillis() = runWithMainLoop {
val record = Record(
key = "key",
fields = mapOf(
"field" to "value"
)
)
val memoryCache = MemoryCache(expireAfterMillis = 200)
memoryCache.merge(record, CacheHeaders.NONE)

val cacheRecord = checkNotNull(memoryCache.loadRecord(record.key, CacheHeaders.NONE))
assertEquals(record.key, cacheRecord.key)
assertEquals(record.fields, cacheRecord.fields)

delay(250)
assertNull(memoryCache.loadRecord(record.key, CacheHeaders.NONE))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query AllFilms($after: String, $first: Int?, $before: String, $last: Int) {
query AllFilms($after: String, $first: Int, $before: String, $last: Int) {
allFilms(after: $after, first: $first, before: $before, last: $last) {
totalCount
films {
Expand Down