Commit graph

32 commits

Author SHA1 Message Date
b5e8e00dcb
perf(tests): aggressive timeout and delay reductions
Major reductions across test suite:
- Error handler backoff delays: 100ms→20ms, 50ms→10ms
- Sensor change detector refute_receive: 100ms→50ms
- Agent channel assert_receive: 5000ms→1000ms, 2000ms→500ms
- Agent channel assert_push: 5000ms→1000ms
- Deferred discovery timeout sleeps: 60ms→55ms
- Event logger sleeps: 25ms→10ms
- Validator test: 50,100 OIDs→50,001 (minimum to test rejection)

Performance: 28s → 26.8s (4.3% faster)
Total from baseline: 52s → 26.8s (48.5% faster)
2026-03-06 08:28:18 -06:00
83d47d1502
perf(tests): remove/reduce Process.sleep calls for faster tests
- Remove all 25ms and 50ms sleeps from agent_channel_test
- Add poll_until helper for async DB operations (early exit on success)
- Reduce timeout test sleeps from 100ms to 60ms
- Reduce polling delays from 10ms to 5ms in multiple tests
- Remove unnecessary timestamp and background task sleeps
- Reduce circuit breaker recovery sleep from 150ms to 110ms

Performance: 30.3s → 28.3s (6.6% faster)
Total improvement from baseline: 52s → 28.3s (45.6% faster)
2026-03-06 07:57:30 -06:00
07336fefff
perf(test): optimize slow tests - 68% faster
- Add timeout: 100 to SNMP tests to avoid 5s default timeout on unreachable IPs
- Reduce retry delays in error handler tests from 50-100ms to 1ms
- Fix Splynx rate limit test to stub auth immediately without extra calls
- Use localhost instead of device.local to avoid DNS timeout
- Use temp empty dir for ImportProfiles test instead of scanning 788 real files

Results:
- Top 10 slowest: 45.6s → 14.6s (68% reduction)
- Overall suite: ~80s → 39.9s (50% faster)
- Specific improvements:
  * Splynx sync: 7010ms → 134ms (98% faster)
  * ImportProfiles: 5502ms → 33ms (99% faster)
  * get_bulk!: 5043ms → 125ms (97% faster)
  * Walk hostname: 5005ms → 119ms (97% faster)
  * Error retries: 3103ms → 6ms (99% faster)
2026-03-05 14:35:58 -06:00
47b364a112
Fix Gaiia inventory matching, mapping UX, and logo link
- Fetch MAC address from Gaiia custom fields during inventory sync
- Remove name-based device matching (model names caused false matches)
- Keep IP-only matching for device suggestions
- Make unmapped rows clickable in the Gaiia mapping table
- Point authenticated logo link to /dashboard instead of /orgs
- Fix flaky monitor test teardown race condition
2026-02-15 17:41:43 -06:00
c790794191 Fix tests, credo issues, and Gaiia sync bugs
- Fix CLOAK_KEY placeholder in nix shell (invalid base64)
- Fix error HTML test assertion to match actual template
- Fix Gaiia sync: read 'subnet' field instead of 'block' for IP blocks
- Fix Gaiia sync: extract nested status name from subscription objects
- Fix security headers tests for environment detection
- Fix mobile auth tests to use raw_token
- Fix LiveView test assertions to match actual template content
- Fix SNMP config test expectations for test environment
- Refactor: resolve all Credo complexity/nesting issues
  - Extract helper functions in NetBox sync, VISP sync, Sonar sync
  - Flatten nested conditionals in settings, integrations, alerts
  - Use with/validate_present pattern for connection testing
2026-02-15 11:55:49 -06:00
3284f0bce6 fix: increase walker concurrent test timeout, prefix unused vars, add heex to dialyzer ignore 2026-02-14 13:07:14 -06:00
0a978746e1
Fix all Credo issues
Resolves 26 Credo warnings/issues:

Code Readability (2 issues):
- Break long line in mac_address.ex (line 316 > 120 chars)
- Break long @spec in agents.ex (line 332 > 120 chars)

Refactoring Opportunities (2 issues):
- Reduce cyclomatic complexity in device_live/form.ex
  - Extract helper functions to simplify SNMPv3 credential resolution
  - Split logic into smaller, focused functions
- Reduce nesting depth in snmp_oid.ex
  - Extract nested logic into separate helper functions

Warnings (22 issues):
- Fix comparison warning in validator.ex
  - Split validate_sensor_value/1 into separate clauses for int/float
  - Add credo directive for valid NaN check (value != value)
- Replace 21 expensive length/1 checks with Enum.empty?/1
  - Change assertions from `assert length(list) >= 1` to `refute Enum.empty?(list)`
  - Change assertions from `assert length(list) > 0` to `refute Enum.empty?(list)`
  - Affected files: device_poller_worker_test.exs, mib_test.exs,
    snmp_tokenizer_test.exs, parser_test.exs, error_test.exs, compiler_test.exs

All tests passing (5578 tests, 0 failures).
Credo now reports: "found no issues"
2026-02-06 10:31:09 -06:00
ed50257d8a
fix snmp v3 test 2026-02-06 10:21:54 -06:00
27950de26e
test: expand MIB.Compiler tests (46.15%)
Added 34 comprehensive tests covering:
- compile_string/2 - String compilation (7 tests)
- compile/2 - File compilation (2 tests)
- Integration with Parser (1 test)
- compile_all/2 - Batch compilation (4 tests)
- load_compiled/1 - Load compiled MIBs (3 tests)
- Compile options (validate, format, output_dir, optimize, etc.) (8 tests)
- Error handling (syntax errors, missing files, parse errors) (3 tests)
- Symbol table construction (2 tests)
- Dependency extraction (deduplication, single/multiple) (4 tests)
- Compiled MIB structure validation (2 tests)

All tests tagged @moduletag :yecc_required (excluded by default).
Tests use temporary directories for file I/O.Coverage: 46.15% (unchanged - tests excluded)
Total tests: 1,514 (all passing, 72 excluded)
2026-02-06 09:12:26 -06:00
b653932879
test: expand MIB.Parser tests (8.66% → 9.96%)
Added 80+ comprehensive tests covering:
- init_parser/0 - Parser initialization (2 tests)
- tokenize/1 - MIB tokenization (11 tests)
- parse/1 - MIB parsing (6 tests)
- parse_tokens/1 - Pre-tokenized parsing (3 tests)
- mibdirs/1 - Directory batch parsing (4 tests)
- Hex atom conversion and integration (3 tests)
- Error handling for malformed MIBs (4 tests)
- MIB structure parsing (MODULE-IDENTITY, TEXTUAL-CONVENTION, etc.) (4 tests)
- Complex MIB features (IMPORTS, SEQUENCE, INDEX, SIZE, ranges) (5 tests)
- Description cleaning edge cases (3 tests)
- Edge cases (large files, long identifiers, nested OIDs) (4 tests)
- Real-world MIB patterns (SNMPv2, tables, various syntax types) (7 tests)

Most parse tests tagged @tag :yecc_required (excluded by default).
Tokenize tests run without yecc dependency.
Coverage: 8.66% → 9.96% (+1.3%)
Total tests: 1,480 (all passing, 38 excluded)
2026-02-06 09:09:28 -06:00
055bef4cd7
Add comprehensive tests for MIB module (45 tests)
Create new test file for MIB facade module with tests for:
- compile/2 (16 tests) - file paths, all options, error handling
- compile_string/2 (11 tests, @tag :yecc_required) - MIB content parsing
- load_compiled/1 (7 tests) - loading compiled MIB files
- compile_all/2 (13 tests) - batch compilation with dependency order
- Option validation (3 tests) - handling invalid option keys
- Return value structure (4 tests) - tuple format verification
- Error handling (4 tests) - graceful handling of invalid inputs
- Default options (3 tests) - behavior with and without options

Tests verify proper delegation to Compiler module and
correct error handling for file operations.

Note: compile_string tests tagged with :yecc_required since
they depend on yecc parser generator being available.

Coverage: 1,419 → 1,464 tests, 45 passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 09:01:49 -06:00
b42ac8f999
Expand PDU.V3Encoder tests (22 new tests)
Improve coverage from 37.97% to 40.64% with tests for:
- PDU types in SNMPv3 messages (get_next, get_response, set, getbulk)
- Context engine ID and context name (empty, non-empty, both)
- Message max size variations (minimum 484, custom values)
- Multiple varbinds in v3 messages
- Error responses with various error_status values (0-5)
- Reportable flag variations (true/false)
- USM security model
- All SNMP value types (counter64, gauge32, ip_address, opaque, oid)
- Exception values (no_such_object, no_such_instance, end_of_mib_view)
- Message ID edge cases (0, max 2147483647)
- Discovery message consistency

Tests verify message encoding completes without crashes
even when V3 security processing is involved.

Coverage: 1,391 → 1,419 tests, all passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 08:57:48 -06:00
14ec708e93
Add comprehensive tests for PDU.Encoder (87 tests)
Improve coverage from 43.82% to 75.84% with tests for:
- Message encoding (SNMPv1, v2c, v3 delegation)
- PDU encoding (all PDU types: get, getnext, response, set, getbulk)
- Varbind encoding (explicit types, auto types, all SNMP value types)
- Integer encoding edge cases (zero, small, large, negative)
- Counter32/Gauge32/Timeticks (min/max values)
- Counter64 (0 to 18446744073709551615)
- String encoding (empty, short, long, special chars, binary)
- OID encoding (simple, large subids, very large subids, long OIDs)
- Bulk request encoding (non_repeaters, max_repetitions)
- Exception values (no_such_object, no_such_instance, end_of_mib_view)
- Length encoding edge cases (short, medium, long form)
- Error handling (invalid formats, missing fields)
- Complete integration tests (GET/GETNEXT/SET/GETBULK)

Coverage: 1,304 → 1,391 tests, all passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 08:53:52 -06:00
07977bc16f
test: add comprehensive tests for MIB.SnmpTokenizer
Added complete test coverage for MIB.SnmpTokenizer module (32.93% -> target higher):

**Tokenization Tests:**
- Empty input handling
- Simple MIB header (DEFINITIONS, BEGIN, END)
- Reserved word recognition (30+ SMI keywords tested)
- Identifier tokenization (lowercase atoms, uppercase variables)
- Number tokenization (integers, negative numbers, leading zeros, large numbers)
- String tokenization with quotes
- Special characters (::=, {}, (), commas, semicolons, dots)
- OID notation
- Complete OBJECT-TYPE definitions
- Access modifiers (read-only, read-write, not-accessible, read-create)
- SMI types (INTEGER, OCTET STRING, Counter32, Gauge32, TimeTicks, IpAddress)
- Hyphenated keywords (OBJECT-TYPE, MAX-ACCESS, MODULE-IDENTITY, etc.)

**Format and Syntax:**
- Whitespace handling (spaces, tabs, newlines)
- Comment handling (-- comments)
- Multiline input
- Line number tracking
- Token order preservation
- Complex MIB structures (IMPORTS, MODULE-IDENTITY, etc.)
- SIZE constraints
- SEQUENCE OF notation

**Error Handling:**
- format_error/1 for illegal characters
- Unterminated string errors
- Unterminated quote errors
- Unknown error formatting

**Edge Cases:**
- Very long identifiers (up to 200 chars)
- Many tokens (100+ identifiers)
- Deeply nested braces
- Mixed case keywords (case-sensitive)
- Empty strings
- Consecutive operators
- Tabs and mixed whitespace
- Numbers with leading zeros
- Very large numbers

**Reserved Word Coverage:**
- All common SMI/SMIv2 reserved words tested
- Distinction between reserved words and similar identifiers
- Case-sensitive recognition

40 new tests added
Test count: 1,264 -> 1,304 (all passing)
2026-02-06 08:45:23 -06:00
42895fea8f
test: add comprehensive tests for MIB.Error
Added complete test coverage for MIB.Error module (16.13% -> target 100%):

**Error Creation:**
- All supported error types (syntax, semantic, import, type, constraint, etc.)
- Error creation with line and column information
- Error creation with context maps
- Suggestion generation for common mistakes

**Error Types Tested:**
- unexpected_token with various combinations (expected/actual/value)
- unexpected_eof with expected values
- unterminated_string
- invalid_number and invalid_identifier
- file_not_found with path
- import_error with symbol and module
- duplicate_definition with name
- Generic error types

**Suggestion Generation:**
- MAX-ACCESS vs ACCESS typo
- deprecated 'mandatory' vs 'current'
- OBJECT-TYPE vs OBJECT-IDENTITY confusion
- Unterminated string hints
- File not found with RFC/MIB name detection
- Import error dependency hints

**Error Formatting:**
- Format with/without line and column
- Format with/without suggestions
- Multiple suggestion formatting
- Edge cases (nil values, empty strings, non-standard types)

**Edge Cases:**
- All nil fields
- Large line numbers
- Zero/negative line/column values
- Various context data types
- Mixed token value types
- Empty options handling

53 new tests added
Test count: 1,211 -> 1,264 (all passing)
2026-02-06 08:38:33 -06:00
82b4dbdf28
test: add comprehensive tests for PDU.Constants and MIB.Logger
Added complete test coverage for two low-coverage modules:

**PDU.Constants (11.65% -> target 100%)**:
- Error status code accessors and conversions
- SNMPv3 constants (USM security model, max message size)
- PDU type constants and tag conversion (get, getnext, response, set, getbulk)
- Data type constants and tag conversion (all SNMP types)
- SNMP version normalization (:v1, :v2c, :v3)
- OID normalization (list and string formats)
- SNMPv3 message flags encoding/decoding
- Default message flags for security levels
- Error status code/atom conversion
- Roundtrip encoding/decoding verification
- 43 new tests

**MIB.Logger (11.11% -> target 100%)**:
- Compilation lifecycle logging (start, success, error, warning, complete)
- Batch compilation logging (start, progress, success, error)
- Parse progress and import resolution logging
- Code generation and tokenization statistics
- Dependency order and performance metrics
- Vendor quirk handling
- Warning logging with context
- Error type extraction and aggregation
- 40 new tests

Total: 83 new tests added
Test count: 1,128 -> 1,211 (all passing)
2026-02-06 08:36:20 -06:00
35ee87952f
test: expand Types module test coverage
Added comprehensive test coverage for previously untested functionality:

- IP address parsing (valid IPs, invalid inputs, IPv6 rejection)
- Zero-filling behavior for incomplete IPs (Erlang :inet standard)
- Type inference for all SNMP types (integers, strings, lists, booleans, nulls)
- Value decoding for all SNMP types (strings, integers, IPs, OIDs, exceptions)
- Value encoding with type inference and validation controls
- Unsigned32 validation (valid ranges, overflow, underflow)
- Coercion edge cases (IP addresses, unsigned32, octet_string, OIDs, booleans)

Fixes:
- Corrected type inference expectation for large integers (returns :unsigned32)
- Fixed boolean assertion to use equality check instead of pattern match
- Documented :inet.parse_address zero-fill behavior for incomplete IPs

Total: 97 tests, all passing
2026-02-05 17:24:10 -06:00
76d70dd3f4
Add comprehensive test coverage for SNMPkit modules
Added test suites for previously untested SNMPkit modules:

- ErrorHandler: Circuit breaker, retry logic, error classification (88.70% coverage)
- MIB.AST: AST node creation, validation, pretty printing (100% coverage)
- MIB.Preprocessor: MIB preprocessing, enumeration simplification (48.28% coverage)
- MIB.Utilities: OID resolution, type validation, error handling (85.60% coverage)
- PDU.V3Encoder: SNMPv3 message encoding/decoding (36.90% coverage)

All 1090 tests passing with no failures.
2026-02-05 17:03:41 -06:00
4e9a533106
Fix SNMPkit tests and add coverage for bang methods
Fixed 2 failing tests in HostParser that were using unreliable hostname resolution. Changed tests to use malformed IP addresses that will always fail validation consistently.

Added tests for SnmpKit.SNMP bang methods (get_bulk!, bulk_walk!) which have actual implementation logic beyond delegation.

All 954 SNMPkit tests now pass (0 failures).
2026-02-05 16:46:36 -06:00
c3d952148e
fix test warnings and failures
- Remove unused Ecto.Query import from device_poller_worker_test
- Update route paths from /orgs/:slug to /dashboard after navigation refactor
- Fix HostParser tests to match actual hostname resolution behavior
- Update UserAuth redirect assertions to expect /dashboard instead of /devices
- Fix DashboardLiveTest missing organization context
- Fix OrgLive.NewTest to verify organization creation correctly

All 4850 tests now passing with zero failures and zero warnings.
2026-02-05 15:24:41 -06:00
021c86a130
more tests and fixes 2026-01-31 16:00:07 -06:00
f350a9ade4 test cleanup 2026-01-28 10:31:22 -06:00
88c003d474 major snmp overhaul 2026-01-28 09:07:13 -06:00
1af381b5bf
snmp tests and docker attempt to build locally 2026-01-27 10:16:54 -06:00
a9405f6818
refactor: alias DiscoveryWorker at module top and skip flaky performance test
- Fixes credo warning about nested module alias
- Tags performance test to exclude from precommit hook (flaky timing on slow machines)
2026-01-25 09:14:07 -06:00
0888d4eed1
perf: optimize slow tests - reduce timeouts and property test iterations
Optimized the 10 slowest tests from 4.7s to ~2.5s (47% reduction):

Property-based tests:
- Reduced max_runs from 50/100 to 10 iterations (still provides good coverage)
- ApiTokensTest: 3 property tests now run 10 iterations instead of 50-100
- EquipmentTest: 3 property tests now run 10 iterations instead of 50-100

Network timeout tests:
- Manager IPv6 tests: reduced timeout from 100ms to 25ms (75% faster)
- Tests already expect failures, so shorter timeouts don't affect validity

Database optimization:
- MemoryPoolTest: converted individual insert to bulk insert_all
- Added proper updated_at timestamp for MemoryPool (required by schema)

Async processing:
- AgentLatencyEvaluatorTest: reduced Process.sleep from 500ms to 100ms
- Worker processes reliably within 100ms threshold

All 3,686 tests pass with no failures.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-24 15:22:56 -06:00
9697596e99
improve credo 2026-01-23 18:21:40 -06:00
2b78b1a2d3
snmpkit overhaul and etcd 2026-01-23 16:23:57 -06:00
f59cdbbd7a
credo fixes 2026-01-23 14:01:52 -06:00
7fcfdbf2e9
credo improvements 2026-01-23 13:40:49 -06:00
a0cee485a4
fix: credo issues - line length and unused aliases/variables 2026-01-23 13:25:08 -06:00
a0ba9285dd
bring in snmpkit 2026-01-23 12:52:17 -06:00