-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix concurrent gauge creation (#7116)
* Added failing test. CHANGELOG_BEGIN CHANGELOG_END * Fixed test. * Added missing header. * Reformatted. * Fixed concurrency issue for CacheMetrics as well. * Reworded test case description a bit. * Code tidying. * Use da_scala_test_suite instead.
- Loading branch information
Showing
5 changed files
with
75 additions
and
8 deletions.
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
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
27 changes: 27 additions & 0 deletions
27
ledger/metrics/src/test/scala/com/daml/metrics/CacheMetricsSpec.scala
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,27 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.metrics | ||
|
||
import com.codahale.metrics.MetricRegistry | ||
import org.scalatest.{AsyncWordSpec, Matchers} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class CacheMetricsSpec extends AsyncWordSpec with Matchers { | ||
"gauge registrations" should { | ||
"succeed on multiple threads in parallel for the same metric registry" in { | ||
val cacheMetrics = new CacheMetrics(new MetricRegistry, MetricName.DAML) | ||
implicit val executionContext: ExecutionContext = ExecutionContext.global | ||
val instances = | ||
(1 to 1000).map(_ => | ||
Future { | ||
cacheMetrics.registerSizeGauge(() => 1L) | ||
cacheMetrics.registerWeightGauge(() => 2L) | ||
}) | ||
Future.sequence(instances).map { _ => | ||
succeed | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ledger/metrics/src/test/scala/com/daml/metrics/MetricsSpec.scala
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,24 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.metrics | ||
|
||
import com.codahale.metrics.MetricRegistry | ||
import org.scalatest.{AsyncWordSpec, Matchers} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class MetricsSpec extends AsyncWordSpec with Matchers { | ||
"gauge registration" should { | ||
"succeed on multiple threads in parallel for the same metric name" in { | ||
val metrics = new Metrics(new MetricRegistry) | ||
implicit val executionContext: ExecutionContext = ExecutionContext.global | ||
val metricName = MetricName.DAML :+ "a" :+ "test" | ||
val instances = | ||
(1 to 1000).map(_ => Future(metrics.gauge[Double](metricName, () => () => 1.0))) | ||
Future.sequence(instances).map { _ => | ||
succeed | ||
} | ||
} | ||
} | ||
} |