-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial API testing for distributed context.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
76 changes: 76 additions & 0 deletions
76
opentelemetry-api/tests/distributedcontext/test_distributed_context.py
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,76 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from opentelemetry import distributedcontext | ||
|
||
|
||
class TestEntryMetadata(unittest.TestCase): | ||
def test_entry_ttl_no_propagation(self): | ||
metadata = distributedcontext.EntryMetadata( | ||
distributedcontext.EntryMetadata.NO_PROPAGATION, | ||
) | ||
self.assertEqual(metadata.entry_ttl, 0) | ||
|
||
def test_entry_ttl_unlimited_propagation(self): | ||
metadata = distributedcontext.EntryMetadata( | ||
distributedcontext.EntryMetadata.UNLIMITED_PROPAGATION, | ||
) | ||
self.assertEqual(metadata.entry_ttl, -1) | ||
|
||
|
||
class TestEntryKey(unittest.TestCase): | ||
def test_create_too_long(self): | ||
with self.assertRaises(ValueError): | ||
distributedcontext.EntryKey.create("a" * 256) | ||
|
||
def test_create_invalid_character(self): | ||
with self.assertRaises(ValueError): | ||
distributedcontext.EntryKey.create("\x00") | ||
|
||
def test_create_valid(self): | ||
key = distributedcontext.EntryKey.create("ok") | ||
self.assertEqual(key, "ok") | ||
|
||
def test_key_new(self): | ||
key = distributedcontext.EntryKey("ok") | ||
self.assertEqual(key, "ok") | ||
|
||
|
||
class TestEntryValue(unittest.TestCase): | ||
def test_create_invalid_character(self): | ||
with self.assertRaises(ValueError): | ||
distributedcontext.EntryValue.create("\x00") | ||
|
||
def test_create_valid(self): | ||
key = distributedcontext.EntryValue.create("ok") | ||
self.assertEqual(key, "ok") | ||
|
||
def test_key_new(self): | ||
key = distributedcontext.EntryValue("ok") | ||
self.assertEqual(key, "ok") | ||
|
||
|
||
class TestDistributedContextManager(unittest.TestCase): | ||
def setUp(self): | ||
self.manager = distributedcontext.DistributedContextManager() | ||
|
||
def test_get_current_context(self): | ||
self.assertIsNone(self.manager.get_current_context()) | ||
|
||
def test_use_context(self): | ||
o = object() | ||
with self.manager.use_context(o) as output: | ||
self.assertIs(output, o) |